# Importing Libraries
import pandas as pd
import numpy as np
import geopandas as gpd
import matplotlib.pyplot as plt
import plotly.express as px
import seaborn as sns
# Reading the Dataset File in csv format
# Skipping the starting 4 rows of data as it's empty
df_gdp = pd.read_csv("API_NY.GDP.MKTP.KD_DS2_en_csv_v2_1622113.csv",skiprows = 4)
df_pop = pd.read_csv("API_SP.POP.TOTL_DS2_en_csv_v2_1637443.csv",skiprows = 4)
# Checking the shape/dimensions of the population data
print(df_pop.shape)
# Checking the shape/dimensions of the GDP data
print(df_gdp.shape)
col_list = list(df_gdp.columns)
col_list.remove('Country Name')
col_list.remove('Country Code')
col_list.remove('Indicator Name')
col_list.remove('Indicator Code')
for year in col_list:
df_gdp.rename(columns = {year:int(eval(year))}, inplace = True)
df_pop.rename(columns = {str(int(eval(year))):int(eval(year))}, inplace = True)
(264, 65) (264, 65)
# Creating copy of the Country Name and Country Code
df = df_gdp[['Country Name', 'Country Code']].copy()
#Displaying the Created Dataframe
df
| Country Name | Country Code | |
|---|---|---|
| 0 | Aruba | ABW |
| 1 | Afghanistan | AFG |
| 2 | Angola | AGO |
| 3 | Albania | ALB |
| 4 | Andorra | AND |
| ... | ... | ... |
| 259 | Kosovo | XKX |
| 260 | Yemen, Rep. | YEM |
| 261 | South Africa | ZAF |
| 262 | Zambia | ZMB |
| 263 | Zimbabwe | ZWE |
264 rows × 2 columns
# Calculating the GDP per Capita for the years 1995,2005,2015 and storing them into dataframes
df['gdp_capita_1995'] = np.where(df_gdp['Country Name'] == df_pop['Country Name'],
df_gdp[1995] / df_pop[1995], 'False')
df['gdp_capita_2005'] = np.where(df_gdp['Country Name'] == df_pop['Country Name'],
df_gdp[2005] / df_pop[2005], 'False')
df['gdp_capita_2015'] = np.where(df_gdp['Country Name'] == df_pop['Country Name'],
df_gdp[2015] / df_pop[2015], 'False')
#Replacing all the 'nan' (null) values with 0 to prevent calculation issues
df=df.replace('nan', 0)
df
| Country Name | Country Code | gdp_capita_1995 | gdp_capita_2005 | gdp_capita_2015 | |
|---|---|---|---|---|---|
| 0 | Aruba | ABW | 26705.18132102485 | 26979.885398426486 | 25822.251374531585 |
| 1 | Afghanistan | AFG | 0 | 357.23471990810737 | 574.1841142713246 |
| 2 | Angola | AGO | 1922.4165974041543 | 2883.978817683927 | 3748.3206229516086 |
| 3 | Albania | ALB | 1703.2818447548516 | 3062.673882995344 | 4524.373085871747 |
| 4 | Andorra | AND | 32577.067361785434 | 46880.80610483472 | 42140.96179846432 |
| ... | ... | ... | ... | ... | ... |
| 259 | Kosovo | XKX | 0 | 2682.076960915241 | 3816.962447785366 |
| 260 | Yemen, Rep. | YEM | 1060.7228689724586 | 1243.4310885395528 | 785.33845841531 |
| 261 | South Africa | ZAF | 5615.299120399583 | 6729.827466025959 | 7556.788578822294 |
| 262 | Zambia | ZMB | 909.583374402126 | 1126.0319364238953 | 1641.0069847993254 |
| 263 | Zimbabwe | ZWE | 1345.9928763502442 | 971.2667230325109 | 1234.1033522311745 |
264 rows × 5 columns
# Using the dataset naturalearth_lowres' which comes default with geopanda
# Since the provided dataset also had values which could badly impact the result
# There was more than 250 rows of data while there are less than 200 recognized territories in world
# The dataset provided by geopanda has the correct data which can be compared with the present dataset
# The 'naturalearth_lowres' dataset also contains the 'Geometry' which is a necessary value for generating maps
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
world.head()
| pop_est | continent | name | iso_a3 | gdp_md_est | geometry | |
|---|---|---|---|---|---|---|
| 0 | 920938 | Oceania | Fiji | FJI | 8374.0 | MULTIPOLYGON (((180.00000 -16.06713, 180.00000... |
| 1 | 53950935 | Africa | Tanzania | TZA | 150600.0 | POLYGON ((33.90371 -0.95000, 34.07262 -1.05982... |
| 2 | 603253 | Africa | W. Sahara | ESH | 906.5 | POLYGON ((-8.66559 27.65643, -8.66512 27.58948... |
| 3 | 35623680 | North America | Canada | CAN | 1674000.0 | MULTIPOLYGON (((-122.84000 49.00000, -122.9742... |
| 4 | 326625791 | North America | United States of America | USA | 18560000.0 | MULTIPOLYGON (((-122.84000 49.00000, -120.0000... |
# Checking the shape of world dataframe
world.shape
(177, 6)
# Renaming the column 'iso_a3' to 'Country Code' to match the dataframe of both geopanda and the dataframe already created from the provided dataset
df.rename(columns = {'Country Code':'iso_a3'}, inplace = True)
# Performing inner join with both the datasets with the help of common country codes
df_final = pd.merge(world.drop_duplicates(),df,how='inner',on='iso_a3')
# Removing unnecessary columns from the data frame
df_final.drop(['pop_est', 'continent', 'gdp_md_est', 'Country Name'], axis = 1, inplace=True)
# Converting String Datatype to float
df_final["gdp_capita_1995"] = df_final["gdp_capita_1995"].astype(float)
df_final["gdp_capita_2005"] = df_final["gdp_capita_2005"].astype(float)
df_final["gdp_capita_2015"] = df_final["gdp_capita_2015"].astype(float)
# Plotting choropleth map with 'gdp per capita of 1995' using Geopandas with legend
df_final.plot(column='gdp_capita_1995', figsize=(16, 12), legend = True, cmap='rocket', edgecolor="white");
df_final.sort_values(by=['gdp_capita_1995']).head(11)
| name | iso_a3 | geometry | gdp_capita_1995 | gdp_capita_2005 | gdp_capita_2015 | |
|---|---|---|---|---|---|---|
| 166 | S. Sudan | SSD | POLYGON ((30.83385 3.50917, 29.95350 4.17370, ... | 0.0 | 0.000000 | 730.932043 |
| 20 | Timor-Leste | TLS | POLYGON ((124.96868 -8.89279, 125.08625 -8.656... | 0.0 | 625.442712 | 908.961090 |
| 156 | Libya | LBY | POLYGON ((25.00000 22.00000, 25.00000 20.00304... | 0.0 | 10642.896569 | 5899.899647 |
| 158 | Djibouti | DJI | POLYGON ((42.35156 12.54223, 42.77964 12.45542... | 0.0 | 0.000000 | 0.000000 |
| 58 | Liberia | LBR | POLYGON ((-8.43930 7.68604, -8.48545 7.39521, ... | 0.0 | 438.247567 | 571.453130 |
| 11 | Somalia | SOM | POLYGON ((41.58513 -1.68325, 40.99300 -0.85829... | 0.0 | 0.000000 | 0.000000 |
| 80 | Qatar | QAT | POLYGON ((50.81011 24.75474, 50.74391 25.48242... | 0.0 | 61649.392838 | 65137.057391 |
| 103 | Syria | SYR | POLYGON ((35.71992 32.70919, 35.70080 32.71601... | 0.0 | 0.000000 | 0.000000 |
| 129 | New Caledonia | NCL | POLYGON ((165.77999 -21.08000, 166.59999 -21.7... | 0.0 | 0.000000 | 0.000000 |
| 98 | Afghanistan | AFG | POLYGON ((66.51861 37.36278, 67.07578 37.35614... | 0.0 | 357.234720 | 574.184114 |
| 164 | Montenegro | MNE | POLYGON ((20.07070 42.58863, 19.80161 42.50009... | 0.0 | 5599.877113 | 7279.882579 |
df_final.sort_values(by=['gdp_capita_1995']).tail(11)
| name | iso_a3 | geometry | gdp_capita_1995 | gdp_capita_2005 | gdp_capita_2015 | |
|---|---|---|---|---|---|---|
| 143 | Brunei | BRN | POLYGON ((115.45071 5.44773, 115.40570 4.95523... | 37713.689941 | 36329.498278 | 32873.467001 |
| 105 | Sweden | SWE | POLYGON ((11.02737 58.85615, 11.46827 59.43239... | 37870.918758 | 50268.175713 | 56339.994297 |
| 132 | Australia | AUS | MULTIPOLYGON (((147.68926 -40.80826, 148.28907... | 38095.129533 | 48813.887763 | 55079.892116 |
| 3 | United States of America | USA | MULTIPOLYGON (((-122.84000 49.00000, -120.0000... | 38369.161843 | 48499.812376 | 52116.738813 |
| 125 | Netherlands | NLD | POLYGON ((6.90514 53.48216, 7.09205 53.14404, ... | 38676.069942 | 48437.879571 | 51871.576501 |
| 149 | Japan | JPN | MULTIPOLYGON (((141.88460 39.18086, 140.95949 ... | 40368.712282 | 44393.626384 | 47102.580878 |
| 81 | Kuwait | KWT | POLYGON ((47.97452 29.97582, 48.18319 29.53448... | 41801.258070 | 47987.458714 | 35969.349311 |
| 136 | Denmark | DNK | MULTIPOLYGON (((9.92191 54.98310, 9.28205 54.8... | 49122.869161 | 58792.660458 | 60402.129248 |
| 122 | Switzerland | CHE | POLYGON ((9.59423 47.52506, 9.63293 47.34760, ... | 61773.096309 | 70471.438518 | 76553.282138 |
| 79 | United Arab Emirates | ARE | POLYGON ((51.57952 24.24550, 51.75744 24.29407... | 62681.609068 | 56092.920219 | 40247.747141 |
| 123 | Luxembourg | LUX | POLYGON ((6.04307 50.12805, 6.24275 49.90223, ... | 74776.805409 | 101380.774640 | 107638.212260 |
# Plotting choropleth map with 'gdp per capita of 2005' using Geopandas with legend
df_final.plot(column='gdp_capita_2005', figsize=(16, 12), legend = True, cmap='rocket', edgecolor="white")
<matplotlib.axes._subplots.AxesSubplot at 0x7f0b47c46320>
df_final.sort_values(by=['gdp_capita_2005']).tail(11)
| name | iso_a3 | geometry | gdp_capita_1995 | gdp_capita_2005 | gdp_capita_2015 | |
|---|---|---|---|---|---|---|
| 81 | Kuwait | KWT | POLYGON ((47.97452 29.97582, 48.18319 29.53448... | 41801.258070 | 47987.458714 | 35969.349311 |
| 125 | Netherlands | NLD | POLYGON ((6.90514 53.48216, 7.09205 53.14404, ... | 38676.069942 | 48437.879571 | 51871.576501 |
| 3 | United States of America | USA | MULTIPOLYGON (((-122.84000 49.00000, -120.0000... | 38369.161843 | 48499.812376 | 52116.738813 |
| 132 | Australia | AUS | MULTIPOLYGON (((147.68926 -40.80826, 148.28907... | 38095.129533 | 48813.887763 | 55079.892116 |
| 105 | Sweden | SWE | POLYGON ((11.02737 58.85615, 11.46827 59.43239... | 37870.918758 | 50268.175713 | 56339.994297 |
| 128 | Ireland | IRL | POLYGON ((-6.19788 53.86757, -6.03299 53.15316... | 29694.646998 | 52276.244332 | 65432.734445 |
| 79 | United Arab Emirates | ARE | POLYGON ((51.57952 24.24550, 51.75744 24.29407... | 62681.609068 | 56092.920219 | 40247.747141 |
| 136 | Denmark | DNK | MULTIPOLYGON (((9.92191 54.98310, 9.28205 54.8... | 49122.869161 | 58792.660458 | 60402.129248 |
| 80 | Qatar | QAT | POLYGON ((50.81011 24.75474, 50.74391 25.48242... | 0.000000 | 61649.392838 | 65137.057391 |
| 122 | Switzerland | CHE | POLYGON ((9.59423 47.52506, 9.63293 47.34760, ... | 61773.096309 | 70471.438518 | 76553.282138 |
| 123 | Luxembourg | LUX | POLYGON ((6.04307 50.12805, 6.24275 49.90223, ... | 74776.805409 | 101380.774640 | 107638.212260 |
# Plotting choropleth map with 'gdp per capita of 2015' using Geopandas with legend
df_final.plot(column='gdp_capita_2015', figsize=(16, 12), legend = True, cmap='rocket', edgecolor="white")
<matplotlib.axes._subplots.AxesSubplot at 0x7f0b47f86668>
df_final.sort_values(by=['gdp_capita_2015']).head(11)
| name | iso_a3 | geometry | gdp_capita_1995 | gdp_capita_2005 | gdp_capita_2015 | |
|---|---|---|---|---|---|---|
| 11 | Somalia | SOM | POLYGON ((41.58513 -1.68325, 40.99300 -0.85829... | 0.000000 | 0.000000 | 0.000000 |
| 36 | Venezuela | VEN | POLYGON ((-60.73357 5.20028, -60.60118 4.91810... | 12692.596083 | 12400.774758 | 0.000000 |
| 148 | Eritrea | ERI | POLYGON ((36.42951 14.42211, 36.32322 14.82249... | 568.323537 | 584.570025 | 0.000000 |
| 103 | Syria | SYR | POLYGON ((35.71992 32.70919, 35.70080 32.71601... | 0.000000 | 0.000000 | 0.000000 |
| 129 | New Caledonia | NCL | POLYGON ((165.77999 -21.08000, 166.59999 -21.7... | 0.000000 | 0.000000 | 0.000000 |
| 90 | North Korea | PRK | MULTIPOLYGON (((130.78000 42.22001, 130.78000 ... | 0.000000 | 0.000000 | 0.000000 |
| 158 | Djibouti | DJI | POLYGON ((42.35156 12.54223, 42.77964 12.45542... | 0.000000 | 0.000000 | 0.000000 |
| 70 | Burundi | BDI | POLYGON ((30.46967 -2.41385, 30.52766 -2.80762... | 262.375066 | 221.096375 | 228.432544 |
| 61 | Central African Rep. | CAF | POLYGON ((27.37423 5.23394, 27.04407 5.12785, ... | 446.767392 | 417.501900 | 346.693797 |
| 10 | Dem. Rep. Congo | COD | POLYGON ((29.34000 -4.49998, 29.51999 -5.41998... | 401.185558 | 300.562422 | 411.020573 |
| 59 | Sierra Leone | SLE | POLYGON ((-13.24655 8.90305, -12.71196 9.34271... | 315.935044 | 353.889419 | 441.137664 |
# Reading data from datasets and preprocessing
df_gdp = pd.ExcelFile("API_NY.GDP.MKTP.KD_DS2_en_csv_v2_1622113.xlsx")
df_pop = pd.ExcelFile("API_SP.POP.TOTL_DS2_en_csv_v2_1637443.xlsx")
df_gdp = df_gdp.parse('Sheet1', skiprows=4, index_col=None, na_values=['NA'])
df_pop = df_pop.parse('Sheet1', skiprows=4, index_col=None, na_values=['NA'])
# converting or replacing nan to 0
df_gdp = df_gdp.replace(np.nan, 0)
df_pop = df_pop.replace(np.nan, 0)
# Reading data from dataset by geopandas
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
world.head()
| pop_est | continent | name | iso_a3 | gdp_md_est | geometry | |
|---|---|---|---|---|---|---|
| 0 | 920938 | Oceania | Fiji | FJI | 8374.0 | MULTIPOLYGON (((180.00000 -16.06713, 180.00000... |
| 1 | 53950935 | Africa | Tanzania | TZA | 150600.0 | POLYGON ((33.90371 -0.95000, 34.07262 -1.05982... |
| 2 | 603253 | Africa | W. Sahara | ESH | 906.5 | POLYGON ((-8.66559 27.65643, -8.66512 27.58948... |
| 3 | 35623680 | North America | Canada | CAN | 1674000.0 | MULTIPOLYGON (((-122.84000 49.00000, -122.9742... |
| 4 | 326625791 | North America | United States of America | USA | 18560000.0 | MULTIPOLYGON (((-122.84000 49.00000, -120.0000... |
# Renaming the column 'iso_a3' to 'Country Code'
world.rename(columns = {'iso_a3' : 'Country Code'}, inplace = True)
world
| pop_est | continent | name | Country Code | gdp_md_est | geometry | |
|---|---|---|---|---|---|---|
| 0 | 920938 | Oceania | Fiji | FJI | 8374.0 | MULTIPOLYGON (((180.00000 -16.06713, 180.00000... |
| 1 | 53950935 | Africa | Tanzania | TZA | 150600.0 | POLYGON ((33.90371 -0.95000, 34.07262 -1.05982... |
| 2 | 603253 | Africa | W. Sahara | ESH | 906.5 | POLYGON ((-8.66559 27.65643, -8.66512 27.58948... |
| 3 | 35623680 | North America | Canada | CAN | 1674000.0 | MULTIPOLYGON (((-122.84000 49.00000, -122.9742... |
| 4 | 326625791 | North America | United States of America | USA | 18560000.0 | MULTIPOLYGON (((-122.84000 49.00000, -120.0000... |
| ... | ... | ... | ... | ... | ... | ... |
| 172 | 7111024 | Europe | Serbia | SRB | 101800.0 | POLYGON ((18.82982 45.90887, 18.82984 45.90888... |
| 173 | 642550 | Europe | Montenegro | MNE | 10610.0 | POLYGON ((20.07070 42.58863, 19.80161 42.50009... |
| 174 | 1895250 | Europe | Kosovo | -99 | 18490.0 | POLYGON ((20.59025 41.85541, 20.52295 42.21787... |
| 175 | 1218208 | North America | Trinidad and Tobago | TTO | 43570.0 | POLYGON ((-61.68000 10.76000, -61.10500 10.890... |
| 176 | 13026129 | Africa | S. Sudan | SSD | 20880.0 | POLYGON ((30.83385 3.50917, 29.95350 4.17370, ... |
177 rows × 6 columns
df_gdp = pd.merge(world.drop_duplicates(),df_gdp,how='inner',on='Country Code')
df_pop = pd.merge(world.drop_duplicates(),df_pop,how='inner',on='Country Code')
# Dropping unnecessary columns
df_gdp.drop(['pop_est', 'continent', 'gdp_md_est', 'name', 2020], axis = 1, inplace=True)
df_pop.drop(['pop_est', 'continent', 'gdp_md_est', 'name', 2020], axis = 1, inplace=True)
df_gdp
| Country Code | geometry | Country Name | Indicator Name | Indicator Code | 1960 | 1961 | 1962 | 1963 | 1964 | ... | 2010 | 2011 | 2012 | 2013 | 2014 | 2015 | 2016 | 2017 | 2018 | 2019 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | FJI | MULTIPOLYGON (((180.00000 -16.06713, 180.00000... | Fiji | GDP (constant 2010 US$) | NY.GDP.MKTP.KD | 6.979477e+08 | 7.224986e+08 | 7.485526e+08 | 7.961514e+08 | 8.349819e+08 | ... | 3.140509e+09 | 3.225464e+09 | 3.270986e+09 | 3.425841e+09 | 3.617809e+09 | 3.786536e+09 | 3.881570e+09 | 4.092174e+09 | 4.236473e+09 | 4.281518e+09 |
| 1 | TZA | POLYGON ((33.90371 -0.95000, 34.07262 -1.05982... | Tanzania | GDP (constant 2010 US$) | NY.GDP.MKTP.KD | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | ... | 3.201425e+10 | 3.447043e+10 | 3.602166e+10 | 3.846449e+10 | 4.105410e+10 | 4.358329e+10 | 4.657621e+10 | 4.973672e+10 | 5.244487e+10 | 5.548215e+10 |
| 2 | CAN | MULTIPOLYGON (((-122.84000 49.00000, -122.9742... | Canada | GDP (constant 2010 US$) | NY.GDP.MKTP.KD | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | ... | 1.613464e+12 | 1.664238e+12 | 1.693566e+12 | 1.733011e+12 | 1.782749e+12 | 1.794501e+12 | 1.812471e+12 | 1.869939e+12 | 1.907593e+12 | 1.939183e+12 |
| 3 | USA | MULTIPOLYGON (((-122.84000 49.00000, -120.0000... | United States | GDP (constant 2010 US$) | NY.GDP.MKTP.KD | 3.173051e+12 | 3.246031e+12 | 3.444039e+12 | 3.595577e+12 | 3.804120e+12 | ... | 1.499205e+13 | 1.522455e+13 | 1.556704e+13 | 1.585380e+13 | 1.624253e+13 | 1.671046e+13 | 1.697235e+13 | 1.734863e+13 | 1.785648e+13 | 1.827317e+13 |
| 4 | KAZ | POLYGON ((87.35997 49.21498, 86.59878 48.54918... | Kazakhstan | GDP (constant 2010 US$) | NY.GDP.MKTP.KD | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | ... | 1.480473e+11 | 1.590029e+11 | 1.666350e+11 | 1.766331e+11 | 1.840517e+11 | 1.862603e+11 | 1.883092e+11 | 1.960298e+11 | 2.040671e+11 | 2.132501e+11 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 162 | MKD | POLYGON ((22.38053 42.32026, 22.88137 41.99930... | North Macedonia | GDP (constant 2010 US$) | NY.GDP.MKTP.KD | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | ... | 9.407169e+09 | 9.627286e+09 | 9.583368e+09 | 9.863706e+09 | 1.022167e+10 | 1.061581e+10 | 1.091817e+10 | 1.103628e+10 | 1.133648e+10 | 1.173899e+10 |
| 163 | SRB | POLYGON ((18.82982 45.90887, 18.82984 45.90888... | Serbia | GDP (constant 2010 US$) | NY.GDP.MKTP.KD | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | ... | 4.181947e+10 | 4.267103e+10 | 4.238021e+10 | 4.360611e+10 | 4.291299e+10 | 4.367526e+10 | 4.513416e+10 | 4.605910e+10 | 4.808212e+10 | 5.009537e+10 |
| 164 | MNE | POLYGON ((20.07070 42.58863, 19.80161 42.50009... | Montenegro | GDP (constant 2010 US$) | NY.GDP.MKTP.KD | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | ... | 4.139192e+09 | 4.272824e+09 | 4.156441e+09 | 4.303952e+09 | 4.380722e+09 | 4.529244e+09 | 4.662825e+09 | 4.882745e+09 | 5.130686e+09 | 5.316458e+09 |
| 165 | TTO | POLYGON ((-61.68000 10.76000, -61.10500 10.890... | Trinidad and Tobago | GDP (constant 2010 US$) | NY.GDP.MKTP.KD | 3.397616e+09 | 3.874542e+09 | 3.980799e+09 | 4.203907e+09 | 4.524686e+09 | ... | 2.215795e+10 | 2.209273e+10 | 2.237330e+10 | 2.287201e+10 | 2.266330e+10 | 2.307649e+10 | 2.162349e+10 | 2.112353e+10 | 2.107173e+10 | 2.107123e+10 |
| 166 | SSD | POLYGON ((30.83385 3.50917, 29.95350 4.17370, ... | South Sudan | GDP (constant 2010 US$) | NY.GDP.MKTP.KD | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | ... | 1.460207e+10 | 1.392449e+10 | 7.507789e+09 | 8.493542e+09 | 8.780084e+09 | 7.832418e+09 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 |
167 rows × 65 columns
df_gdp[2015]
0 3.786536e+09
1 4.358329e+10
2 1.794501e+12
3 1.671046e+13
4 1.862603e+11
...
162 1.061581e+10
163 4.367526e+10
164 4.529244e+09
165 2.307649e+10
166 7.832418e+09
Name: 2015, Length: 167, dtype: float64
# Copying 'Country Name', 'Country Code', 'geometry' to create a dataframe
df_2015 = df_pop[['Country Name', 'Country Code', 'geometry', 2015]].copy()
# Calculating gdp-per-capita for 2015
df_2015['gdp_capita_2015'] = np.where(df_gdp['Country Name'] == df_2015['Country Name'],
df_gdp[2015] / df_2015[2015], 'False')
# Copying GDP column from main dataframe to above created dataframe
df_2015['gdp_2015'] = np.where(df_gdp['Country Name'] == df_2015['Country Name'],
df_gdp[2015], 'False')
# Converting String to Float
df_2015['gdp_2015'] = df_2015["gdp_2015"].astype(float)
df_2015.head(10)
| Country Name | Country Code | geometry | 2015 | gdp_capita_2015 | gdp_2015 | |
|---|---|---|---|---|---|---|
| 0 | Fiji | FJI | MULTIPOLYGON (((180.00000 -16.06713, 180.00000... | 868627.0 | 4359.220150833176 | 3.786536e+09 |
| 1 | Tanzania | TZA | POLYGON ((33.90371 -0.95000, 34.07262 -1.05982... | 51482633.0 | 846.5630129838211 | 4.358329e+10 |
| 2 | Canada | CAN | MULTIPOLYGON (((-122.84000 49.00000, -122.9742... | 35702908.0 | 50262.02766579602 | 1.794501e+12 |
| 3 | United States | USA | MULTIPOLYGON (((-122.84000 49.00000, -120.0000... | 320635163.0 | 52116.73881277394 | 1.671046e+13 |
| 4 | Kazakhstan | KAZ | POLYGON ((87.35997 49.21498, 86.59878 48.54918... | 17542806.0 | 10617.474655049025 | 1.862603e+11 |
| 5 | Uzbekistan | UZB | POLYGON ((55.96819 41.30864, 55.92892 44.99586... | 31298900.0 | 2138.5669253595524 | 6.693479e+10 |
| 6 | Papua New Guinea | PNG | MULTIPOLYGON (((141.00021 -2.60015, 142.73525 ... | 8107775.0 | 2400.5039363531673 | 1.946275e+10 |
| 7 | Indonesia | IDN | MULTIPOLYGON (((141.00021 -2.60015, 141.01706 ... | 258383256.0 | 3824.274885236236 | 9.881286e+11 |
| 8 | Argentina | ARG | MULTIPOLYGON (((-68.63401 -52.63637, -68.25000... | 43131966.0 | 10568.157808708256 | 4.558254e+11 |
| 9 | Chile | CHL | MULTIPOLYGON (((-68.63401 -52.63637, -68.63335... | 17969353.0 | 14722.366327630996 | 2.645514e+11 |
# For year 2015,GDP per capita for only the countries having population greater than 300000000
df_2015_300000000 = df_2015.loc[df_2015[2015] > 300000000]
df_2015_300000000['gdp_capita_2015'] = df_2015_300000000['gdp_capita_2015'].astype(float)
df_2015
/home/sarvesh/anaconda3/envs/geospatial/lib/python3.6/site-packages/geopandas/geodataframe.py:853: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
| Country Name | Country Code | geometry | 2015 | gdp_capita_2015 | gdp_2015 | |
|---|---|---|---|---|---|---|
| 0 | Fiji | FJI | MULTIPOLYGON (((180.00000 -16.06713, 180.00000... | 868627.0 | 4359.220150833176 | 3.786536e+09 |
| 1 | Tanzania | TZA | POLYGON ((33.90371 -0.95000, 34.07262 -1.05982... | 51482633.0 | 846.5630129838211 | 4.358329e+10 |
| 2 | Canada | CAN | MULTIPOLYGON (((-122.84000 49.00000, -122.9742... | 35702908.0 | 50262.02766579602 | 1.794501e+12 |
| 3 | United States | USA | MULTIPOLYGON (((-122.84000 49.00000, -120.0000... | 320635163.0 | 52116.73881277394 | 1.671046e+13 |
| 4 | Kazakhstan | KAZ | POLYGON ((87.35997 49.21498, 86.59878 48.54918... | 17542806.0 | 10617.474655049025 | 1.862603e+11 |
| ... | ... | ... | ... | ... | ... | ... |
| 162 | North Macedonia | MKD | POLYGON ((22.38053 42.32026, 22.88137 41.99930... | 2079328.0 | 5105.402235055942 | 1.061581e+10 |
| 163 | Serbia | SRB | POLYGON ((18.82982 45.90887, 18.82984 45.90888... | 7095383.0 | 6155.44816919191 | 4.367526e+10 |
| 164 | Montenegro | MNE | POLYGON ((20.07070 42.58863, 19.80161 42.50009... | 622159.0 | 7279.882579191042 | 4.529244e+09 |
| 165 | Trinidad and Tobago | TTO | POLYGON ((-61.68000 10.76000, -61.10500 10.890... | 1370328.0 | 16840.120801184825 | 2.307649e+10 |
| 166 | South Sudan | SSD | POLYGON ((30.83385 3.50917, 29.95350 4.17370, ... | 10715658.0 | 730.9320426740551 | 7.832418e+09 |
167 rows × 6 columns
df_2015_300000000
| Country Name | Country Code | geometry | 2015 | gdp_capita_2015 | gdp_2015 | |
|---|---|---|---|---|---|---|
| 3 | United States | USA | MULTIPOLYGON (((-122.84000 49.00000, -120.0000... | 3.206352e+08 | 52116.738813 | 1.671046e+13 |
| 93 | India | IND | POLYGON ((97.32711 28.26158, 97.40256 27.88254... | 1.310152e+09 | 1751.664429 | 2.294947e+12 |
| 134 | China | CHN | MULTIPOLYGON (((109.47521 18.19770, 108.65521 ... | 1.371220e+09 | 6500.281937 | 8.913317e+12 |
df_2015_300000000.sort_values(by=['gdp_capita_2015']).tail(10)
| Country Name | Country Code | geometry | 2015 | gdp_capita_2015 | gdp_2015 | |
|---|---|---|---|---|---|---|
| 93 | India | IND | POLYGON ((97.32711 28.26158, 97.40256 27.88254... | 1.310152e+09 | 1751.664429 | 2.294947e+12 |
| 134 | China | CHN | MULTIPOLYGON (((109.47521 18.19770, 108.65521 ... | 1.371220e+09 | 6500.281937 | 8.913317e+12 |
| 3 | United States | USA | MULTIPOLYGON (((-122.84000 49.00000, -120.0000... | 3.206352e+08 | 52116.738813 | 1.671046e+13 |
# For year 2015, GDP per capita for only the countries having population less than 70000000
df_2015_70000000 = df_2015.loc[df_2015[2015] < 70000000]
df_2015_70000000['gdp_capita_2015'] = df_2015_70000000['gdp_capita_2015'].astype(float)
df_2015_70000000
/home/sarvesh/anaconda3/envs/geospatial/lib/python3.6/site-packages/geopandas/geodataframe.py:853: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
| Country Name | Country Code | geometry | 2015 | gdp_capita_2015 | gdp_2015 | |
|---|---|---|---|---|---|---|
| 0 | Fiji | FJI | MULTIPOLYGON (((180.00000 -16.06713, 180.00000... | 868627.0 | 4359.220151 | 3.786536e+09 |
| 1 | Tanzania | TZA | POLYGON ((33.90371 -0.95000, 34.07262 -1.05982... | 51482633.0 | 846.563013 | 4.358329e+10 |
| 2 | Canada | CAN | MULTIPOLYGON (((-122.84000 49.00000, -122.9742... | 35702908.0 | 50262.027666 | 1.794501e+12 |
| 4 | Kazakhstan | KAZ | POLYGON ((87.35997 49.21498, 86.59878 48.54918... | 17542806.0 | 10617.474655 | 1.862603e+11 |
| 5 | Uzbekistan | UZB | POLYGON ((55.96819 41.30864, 55.92892 44.99586... | 31298900.0 | 2138.566925 | 6.693479e+10 |
| ... | ... | ... | ... | ... | ... | ... |
| 162 | North Macedonia | MKD | POLYGON ((22.38053 42.32026, 22.88137 41.99930... | 2079328.0 | 5105.402235 | 1.061581e+10 |
| 163 | Serbia | SRB | POLYGON ((18.82982 45.90887, 18.82984 45.90888... | 7095383.0 | 6155.448169 | 4.367526e+10 |
| 164 | Montenegro | MNE | POLYGON ((20.07070 42.58863, 19.80161 42.50009... | 622159.0 | 7279.882579 | 4.529244e+09 |
| 165 | Trinidad and Tobago | TTO | POLYGON ((-61.68000 10.76000, -61.10500 10.890... | 1370328.0 | 16840.120801 | 2.307649e+10 |
| 166 | South Sudan | SSD | POLYGON ((30.83385 3.50917, 29.95350 4.17370, ... | 10715658.0 | 730.932043 | 7.832418e+09 |
148 rows × 6 columns
df_2015_70000000.sort_values(by=['gdp_capita_2015']).head(10)
| Country Name | Country Code | geometry | 2015 | gdp_capita_2015 | gdp_2015 | |
|---|---|---|---|---|---|---|
| 129 | New Caledonia | NCL | POLYGON ((165.77999 -21.08000, 166.59999 -21.7... | 272400.0 | 0.000000 | 0.000000e+00 |
| 36 | Venezuela, RB | VEN | POLYGON ((-60.73357 5.20028, -60.60118 4.91810... | 30081829.0 | 0.000000 | 0.000000e+00 |
| 90 | Korea, Dem. Peopleâs Rep. | PRK | MULTIPOLYGON (((130.78000 42.22001, 130.78000 ... | 25183833.0 | 0.000000 | 0.000000e+00 |
| 103 | Syrian Arab Republic | SYR | POLYGON ((35.71992 32.70919, 35.70080 32.71601... | 17997408.0 | 0.000000 | 0.000000e+00 |
| 158 | Djibouti | DJI | POLYGON ((42.35156 12.54223, 42.77964 12.45542... | 913993.0 | 0.000000 | 0.000000e+00 |
| 11 | Somalia | SOM | POLYGON ((41.58513 -1.68325, 40.99300 -0.85829... | 13797201.0 | 0.000000 | 0.000000e+00 |
| 70 | Burundi | BDI | POLYGON ((30.46967 -2.41385, 30.52766 -2.80762... | 10160030.0 | 228.432544 | 2.320882e+09 |
| 61 | Central African Republic | CAF | POLYGON ((27.37423 5.23394, 27.04407 5.12785, ... | 4493170.0 | 346.693797 | 1.557754e+09 |
| 59 | Sierra Leone | SLE | POLYGON ((-13.24655 8.90305, -12.71196 9.34271... | 7171914.0 | 441.137664 | 3.163801e+09 |
| 73 | Madagascar | MDG | POLYGON ((49.54352 -12.46983, 49.80898 -12.895... | 24234088.0 | 469.942367 | 1.138862e+10 |
df_2015_70000000.sort_values(by=['gdp_capita_2015']).tail(10)
| Country Name | Country Code | geometry | 2015 | gdp_capita_2015 | gdp_2015 | |
|---|---|---|---|---|---|---|
| 2 | Canada | CAN | MULTIPOLYGON (((-122.84000 49.00000, -122.9742... | 35702908.0 | 50262.027666 | 1.794501e+12 |
| 125 | Netherlands | NLD | POLYGON ((6.90514 53.48216, 7.09205 53.14404, ... | 16939923.0 | 51871.576501 | 8.787005e+11 |
| 132 | Australia | AUS | MULTIPOLYGON (((147.68926 -40.80826, 148.28907... | 23815995.0 | 55079.892116 | 1.311782e+12 |
| 105 | Sweden | SWE | POLYGON ((11.02737 58.85615, 11.46827 59.43239... | 9799186.0 | 56339.994297 | 5.520861e+11 |
| 136 | Denmark | DNK | MULTIPOLYGON (((9.92191 54.98310, 9.28205 54.8... | 5683483.0 | 60402.129248 | 3.432945e+11 |
| 80 | Qatar | QAT | POLYGON ((50.81011 24.75474, 50.74391 25.48242... | 2565710.0 | 65137.057391 | 1.671228e+11 |
| 128 | Ireland | IRL | POLYGON ((-6.19788 53.86757, -6.03299 53.15316... | 4701957.0 | 65432.734445 | 3.076619e+11 |
| 122 | Switzerland | CHE | POLYGON ((9.59423 47.52506, 9.63293 47.34760, ... | 8282396.0 | 76553.282138 | 6.340446e+11 |
| 123 | Luxembourg | LUX | POLYGON ((6.04307 50.12805, 6.24275 49.90223, ... | 569604.0 | 107638.212260 | 6.131116e+10 |
| 148 | Eritrea | ERI | POLYGON ((36.42951 14.42211, 36.32322 14.82249... | 0.0 | NaN | 0.000000e+00 |
# For year 2015,GDP per capita for only the countries having gross GDP between 450000000000 US Dollar and 8920000000000 US Dollar.
df_2015_between = df_2015.loc[(df_2015['gdp_2015'] > 450000000000) & (df_2015['gdp_2015'] < 8920000000000)]
df_2015_between['gdp_capita_2015'] = df_2015_between['gdp_capita_2015'].astype(float)
df_2015_between
/home/sarvesh/anaconda3/envs/geospatial/lib/python3.6/site-packages/geopandas/geodataframe.py:853: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
| Country Name | Country Code | geometry | 2015 | gdp_capita_2015 | gdp_2015 | |
|---|---|---|---|---|---|---|
| 2 | Canada | CAN | MULTIPOLYGON (((-122.840 49.000, -122.974 49.0... | 3.570291e+07 | 50262.027666 | 1.794501e+12 |
| 7 | Indonesia | IDN | MULTIPOLYGON (((141.000 -2.600, 141.017 -5.859... | 2.583833e+08 | 3824.274885 | 9.881286e+11 |
| 8 | Argentina | ARG | MULTIPOLYGON (((-68.634 -52.636, -68.250 -53.1... | 4.313197e+07 | 10568.157809 | 4.558254e+11 |
| 17 | Russian Federation | RUS | MULTIPOLYGON (((178.725 71.099, 180.000 71.516... | 1.440969e+08 | 11537.202127 | 1.662475e+12 |
| 23 | Mexico | MEX | POLYGON ((-117.128 32.535, -115.991 32.612, -1... | 1.218583e+08 | 10037.201490 | 1.223116e+12 |
| 25 | Brazil | BRA | POLYGON ((-53.374 -33.768, -53.651 -33.202, -5... | 2.044718e+08 | 11431.154481 | 2.337348e+12 |
| 51 | Nigeria | NGA | POLYGON ((2.692 6.259, 2.749 7.871, 2.724 8.50... | 1.811374e+08 | 2563.148864 | 4.642822e+11 |
| 91 | Korea, Rep. | KOR | POLYGON ((126.175 37.750, 126.237 37.840, 126.... | 5.101495e+07 | 26063.706487 | 1.329639e+12 |
| 93 | India | IND | POLYGON ((97.327 28.262, 97.403 27.883, 97.052... | 1.310152e+09 | 1751.664429 | 2.294947e+12 |
| 102 | Iran, Islamic Rep. | IRN | POLYGON ((48.568 29.927, 48.015 30.452, 48.005... | 7.849222e+07 | 6070.187284 | 4.764624e+11 |
| 105 | Sweden | SWE | POLYGON ((11.027 58.856, 11.468 59.432, 12.300... | 9.799186e+06 | 56339.994297 | 5.520861e+11 |
| 108 | Poland | POL | POLYGON ((23.484 53.912, 23.528 53.470, 23.805... | 3.798641e+07 | 14646.322070 | 5.563612e+11 |
| 116 | Germany | DEU | POLYGON ((14.120 53.757, 14.353 53.248, 14.075... | 8.168661e+07 | 45321.402953 | 3.702152e+12 |
| 119 | Turkey | TUR | MULTIPOLYGON (((44.773 37.170, 44.293 37.002, ... | 7.852941e+07 | 13853.097134 | 1.087876e+12 |
| 122 | Switzerland | CHE | POLYGON ((9.594 47.525, 9.633 47.348, 9.480 47... | 8.282396e+06 | 76553.282138 | 6.340446e+11 |
| 124 | Belgium | BEL | POLYGON ((6.157 50.804, 6.043 50.128, 5.782 50... | 1.127420e+07 | 45503.351991 | 5.130137e+11 |
| 125 | Netherlands | NLD | POLYGON ((6.905 53.482, 7.092 53.144, 6.843 52... | 1.693992e+07 | 51871.576501 | 8.787005e+11 |
| 127 | Spain | ESP | POLYGON ((-7.454 37.098, -7.537 37.429, -7.167... | 4.644483e+07 | 30549.791814 | 1.418880e+12 |
| 132 | Australia | AUS | MULTIPOLYGON (((147.689 -40.808, 148.289 -40.8... | 2.381600e+07 | 55079.892116 | 1.311782e+12 |
| 134 | China | CHN | MULTIPOLYGON (((109.475 18.198, 108.655 18.508... | 1.371220e+09 | 6500.281937 | 8.913317e+12 |
| 135 | Italy | ITA | MULTIPOLYGON (((10.443 46.894, 11.049 46.751, ... | 6.073058e+07 | 33961.436190 | 2.062498e+12 |
| 137 | United Kingdom | GBR | MULTIPOLYGON (((-6.198 53.868, -6.954 54.074, ... | 6.511622e+07 | 42017.141072 | 2.735997e+12 |
| 149 | Japan | JPN | MULTIPOLYGON (((141.885 39.181, 140.959 38.174... | 1.271410e+08 | 47102.580878 | 5.988669e+12 |
| 152 | Saudi Arabia | SAU | POLYGON ((34.956 29.357, 36.069 29.197, 36.501... | 3.171767e+07 | 21399.104006 | 6.787297e+11 |
# Percentage change in the GDP per capita from 1995 to 2015, for the country having the highest population in 2015?
highest_pop_country = df_2015.loc[df_2015[2015] == df_2015[2015].max()]['Country Name'].values[0]
gdp_1995 = df_gdp.loc[df_gdp['Country Name'] == highest_pop_country][1995]
gdp_2015 = df_gdp.loc[df_gdp['Country Name'] == highest_pop_country][2015]
pop_1995 = df_pop.loc[df_pop['Country Name'] == highest_pop_country][1995]
pop_2015 = df_pop.loc[df_pop['Country Name'] == highest_pop_country][2015]
gdp_percapita_1995 = gdp_1995 / pop_1995
gdp_percapita_2015 = gdp_2015 / pop_2015
percentage_change = ((gdp_percapita_2015 - gdp_percapita_1995) / gdp_percapita_1995) * 100
percentage_change
134 430.700755 dtype: float64
# Present a correlation plot between mean population of each country and mean per capita GDP (from 1995 to 2015). Very briefly interpret the generated plot
years= []
for i in range(1995, 2016):
years.append(i)
col_list = ['Country Name', 'Country Code', 'geometry']
col_list.extend(years)
df_1995_2015 = df_pop[col_list].copy()
df_1995_2015['mean_1995_2015'] = df_1995_2015.mean(axis=1)
df_1995_2015
| Country Name | Country Code | geometry | 1995 | 1996 | 1997 | 1998 | 1999 | 2000 | 2001 | ... | 2007 | 2008 | 2009 | 2010 | 2011 | 2012 | 2013 | 2014 | 2015 | mean_1995_2015 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Fiji | FJI | MULTIPOLYGON (((180.00000 -16.06713, 180.00000... | 775425.0 | 784386.0 | 792736.0 | 800157.0 | 806303.0 | 811006.0 | 813925.0 | ... | 836190.0 | 845361.0 | 853637.0 | 859818.0 | 863449.0 | 865069.0 | 865608.0 | 866453.0 | 868627.0 | 8.288960e+05 |
| 1 | Tanzania | TZA | POLYGON ((33.90371 -0.95000, 34.07262 -1.05982... | 29649135.0 | 30444526.0 | 31192857.0 | 31924196.0 | 32682239.0 | 33499180.0 | 34385856.0 | ... | 40681414.0 | 41853944.0 | 43073834.0 | 44346525.0 | 45673338.0 | 47052481.0 | 48482266.0 | 49959822.0 | 51482633.0 | 3.921122e+07 |
| 2 | Canada | CAN | MULTIPOLYGON (((-122.84000 49.00000, -122.9742... | 29302311.0 | 29610218.0 | 29905948.0 | 30155173.0 | 30401286.0 | 30685730.0 | 31020902.0 | ... | 32889025.0 | 33247118.0 | 33628895.0 | 34004889.0 | 34339328.0 | 34714222.0 | 35082954.0 | 35437435.0 | 35702908.0 | 3.237562e+07 |
| 3 | United States | USA | MULTIPOLYGON (((-122.84000 49.00000, -120.0000... | 266278000.0 | 269394000.0 | 272657000.0 | 275854000.0 | 279040000.0 | 282162411.0 | 284968955.0 | ... | 301231207.0 | 304093966.0 | 306771529.0 | 309321666.0 | 311556874.0 | 313830990.0 | 315993715.0 | 318301008.0 | 320635163.0 | 2.950726e+08 |
| 4 | Kazakhstan | KAZ | POLYGON ((87.35997 49.21498, 86.59878 48.54918... | 15815626.0 | 15577894.0 | 15333703.0 | 15071300.0 | 14928426.0 | 14883626.0 | 14858335.0 | ... | 15484192.0 | 15674000.0 | 16092822.0 | 16321872.0 | 16557201.0 | 16792089.0 | 17035550.0 | 17288285.0 | 17542806.0 | 1.573780e+07 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 162 | North Macedonia | MKD | POLYGON ((22.38053 42.32026, 22.88137 41.99930... | 1983252.0 | 1989443.0 | 1999598.0 | 2012057.0 | 2024394.0 | 2034819.0 | 2042842.0 | ... | 2065426.0 | 2067313.0 | 2069039.0 | 2070741.0 | 2072487.0 | 2074278.0 | 2076067.0 | 2077775.0 | 2079328.0 | 2.048651e+06 |
| 163 | Serbia | SRB | POLYGON ((18.82982 45.90887, 18.82984 45.90888... | 7625357.0 | 7617794.0 | 7596501.0 | 7567745.0 | 7540401.0 | 7516346.0 | 7503433.0 | ... | 7381579.0 | 7350222.0 | 7320807.0 | 7291436.0 | 7234099.0 | 7199077.0 | 7164132.0 | 7130576.0 | 7095383.0 | 7.401309e+06 |
| 164 | Montenegro | MNE | POLYGON ((20.07070 42.58863, 19.80161 42.50009... | 611712.0 | 611003.0 | 609520.0 | 607662.0 | 606001.0 | 604950.0 | 607389.0 | ... | 615875.0 | 616969.0 | 618294.0 | 619428.0 | 620079.0 | 620601.0 | 621207.0 | 621810.0 | 622159.0 | 6.142568e+05 |
| 165 | Trinidad and Tobago | TTO | POLYGON ((-61.68000 10.76000, -61.10500 10.890... | 1254200.0 | 1257549.0 | 1259848.0 | 1261695.0 | 1263933.0 | 1267153.0 | 1271632.0 | ... | 1308451.0 | 1314443.0 | 1320930.0 | 1328147.0 | 1336178.0 | 1344817.0 | 1353700.0 | 1362342.0 | 1370328.0 | 1.301205e+06 |
| 166 | South Sudan | SSD | POLYGON ((30.83385 3.50917, 29.95350 4.17370, ... | 5118083.0 | 5221926.0 | 5411655.0 | 5661942.0 | 5933882.0 | 6199394.0 | 6447793.0 | ... | 8315139.0 | 8736939.0 | 9142259.0 | 9508364.0 | 9830698.0 | 10113647.0 | 10355036.0 | 10554883.0 | 10715658.0 | 7.787995e+06 |
167 rows × 25 columns
# mean of per capita GDP (from 1995 to 2015) of all the countries.
df_1995_2015_gdp = df_pop[['Country Name', 'Country Code', 'geometry']].copy()
for i in years:
df_1995_2015_gdp['gdp_capita_'+str(i)] = np.where(df_gdp['Country Name'] == df_pop['Country Name'],
(df_gdp[i] / df_pop[i]), 'False')
df_1995_2015_gdp['gdp_capita_'+str(i)] = df_1995_2015_gdp['gdp_capita_'+str(i)].astype(float)
df_1995_2015_gdp['mean_1995_2015'] = df_1995_2015_gdp.mean(axis=1)
df_1995_2015_gdp
| Country Name | Country Code | geometry | gdp_capita_1995 | gdp_capita_1996 | gdp_capita_1997 | gdp_capita_1998 | gdp_capita_1999 | gdp_capita_2000 | gdp_capita_2001 | ... | gdp_capita_2007 | gdp_capita_2008 | gdp_capita_2009 | gdp_capita_2010 | gdp_capita_2011 | gdp_capita_2012 | gdp_capita_2013 | gdp_capita_2014 | gdp_capita_2015 | mean_1995_2015 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Fiji | FJI | MULTIPOLYGON (((180.00000 -16.06713, 180.00000... | 3123.207406 | 3235.728509 | 3131.209930 | 3142.497964 | 3392.976318 | 3315.954492 | 3370.143653 | ... | 3661.408756 | 3659.092104 | 3573.392550 | 3652.527437 | 3735.558315 | 3781.184542 | 3957.728169 | 4175.424020 | 4359.220151 | 3587.817869 |
| 1 | Tanzania | TZA | POLYGON ((33.90371 -0.95000, 34.07262 -1.05982... | 465.871823 | 474.318312 | 479.259092 | 485.646147 | 497.455194 | 507.264250 | 524.184857 | ... | 665.188492 | 683.319087 | 698.951985 | 721.911127 | 754.716742 | 765.563356 | 793.372460 | 821.742361 | 846.563013 | 626.194821 |
| 2 | Canada | CAN | MULTIPOLYGON (((-122.84000 49.00000, -122.9742... | 34669.028290 | 34864.030422 | 35996.710250 | 36697.549864 | 37845.739755 | 39338.836897 | 39460.736067 | ... | 48534.174482 | 48495.204037 | 46540.643700 | 47448.013220 | 48464.496279 | 48785.936079 | 49397.523320 | 50306.944612 | 50262.027666 | 43433.125698 |
| 3 | United States | USA | MULTIPOLYGON (((-122.84000 49.00000, -120.0000... | 38369.161843 | 39356.091800 | 40614.405609 | 41942.709509 | 43434.692675 | 44726.965398 | 44728.597475 | ... | 49856.281491 | 49319.478865 | 47648.813250 | 48467.515777 | 48866.053277 | 49603.253474 | 50171.237133 | 51028.824895 | 52116.738813 | 46500.565552 |
| 4 | Kazakhstan | KAZ | POLYGON ((87.35997 49.21498, 86.59878 48.54918... | 3738.469473 | 3814.499327 | 3941.124848 | 3933.557768 | 4078.426793 | 4491.591823 | 5106.634167 | ... | 8523.766205 | 8698.423654 | 8573.708294 | 9070.488253 | 9603.244655 | 9923.422208 | 10368.499299 | 10646.034465 | 10617.474655 | 7077.942789 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 162 | North Macedonia | MKD | POLYGON ((22.38053 42.32026, 22.88137 41.99930... | 3056.985150 | 3083.587747 | 3112.105269 | 3197.333287 | 3315.735917 | 3448.812931 | 3329.899670 | ... | 4193.002270 | 4418.406699 | 4398.889003 | 4542.899717 | 4645.281601 | 4620.098014 | 4751.150066 | 4919.527828 | 5105.402235 | 3915.923665 |
| 163 | Serbia | SRB | POLYGON ((18.82982 45.90887, 18.82984 45.90888... | 3064.033287 | 3259.199460 | 3503.896070 | 3634.716298 | 3304.113228 | 3517.938025 | 3766.399703 | ... | 5472.709444 | 5806.890315 | 5670.955086 | 5735.422857 | 5898.596132 | 5886.894576 | 6086.726445 | 6018.165974 | 6155.448169 | 4740.294153 |
| 164 | Montenegro | MNE | POLYGON ((20.07070 42.58863, 19.80161 42.50009... | 0.000000 | 0.000000 | 5014.106630 | 5275.880660 | 4793.049256 | 4950.219059 | 4984.567213 | ... | 6476.597472 | 6932.072254 | 6516.357664 | 6682.281158 | 6890.773339 | 6697.444578 | 6928.370218 | 7045.113809 | 7279.882579 | 5416.428788 |
| 165 | Trinidad and Tobago | TTO | POLYGON ((-61.68000 10.76000, -61.10500 10.890... | 6873.885353 | 7344.689160 | 7882.808418 | 8510.775012 | 9177.470151 | 9785.909750 | 10157.932547 | ... | 16580.317242 | 17064.531657 | 16234.981232 | 16683.355379 | 16534.268262 | 16636.683831 | 16895.924301 | 16635.540360 | 16840.120801 | 13168.885729 |
| 166 | South Sudan | SSD | POLYGON ((30.83385 3.50917, 29.95350 4.17370, ... | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | ... | 0.000000 | 1508.232641 | 1514.033972 | 1535.708184 | 1416.429434 | 742.342449 | 820.232982 | 831.850462 | 730.932043 | 433.322008 |
167 rows × 25 columns
df_pop_gdp_corr = df_pop[['Country Name', 'Country Code', 'geometry']].copy()
df_pop_gdp_corr['gdp_mean_1995_2015'] = df_1995_2015_gdp['mean_1995_2015']
df_pop_gdp_corr['pop_mean_1995_2015'] = df_1995_2015['mean_1995_2015']
df_pop_gdp_corr
| Country Name | Country Code | geometry | gdp_mean_1995_2015 | pop_mean_1995_2015 | |
|---|---|---|---|---|---|
| 0 | Fiji | FJI | MULTIPOLYGON (((180.00000 -16.06713, 180.00000... | 3587.817869 | 8.288960e+05 |
| 1 | Tanzania | TZA | POLYGON ((33.90371 -0.95000, 34.07262 -1.05982... | 626.194821 | 3.921122e+07 |
| 2 | Canada | CAN | MULTIPOLYGON (((-122.84000 49.00000, -122.9742... | 43433.125698 | 3.237562e+07 |
| 3 | United States | USA | MULTIPOLYGON (((-122.84000 49.00000, -120.0000... | 46500.565552 | 2.950726e+08 |
| 4 | Kazakhstan | KAZ | POLYGON ((87.35997 49.21498, 86.59878 48.54918... | 7077.942789 | 1.573780e+07 |
| ... | ... | ... | ... | ... | ... |
| 162 | North Macedonia | MKD | POLYGON ((22.38053 42.32026, 22.88137 41.99930... | 3915.923665 | 2.048651e+06 |
| 163 | Serbia | SRB | POLYGON ((18.82982 45.90887, 18.82984 45.90888... | 4740.294153 | 7.401309e+06 |
| 164 | Montenegro | MNE | POLYGON ((20.07070 42.58863, 19.80161 42.50009... | 5416.428788 | 6.142568e+05 |
| 165 | Trinidad and Tobago | TTO | POLYGON ((-61.68000 10.76000, -61.10500 10.890... | 13168.885729 | 1.301205e+06 |
| 166 | South Sudan | SSD | POLYGON ((30.83385 3.50917, 29.95350 4.17370, ... | 433.322008 | 7.787995e+06 |
167 rows × 5 columns
import numpy as np
import pandas as pd
import seaborn as sns
from pandas_profiling import ProfileReport
# Geopanda Choropleth
# Plotting Graphs from data frame
df_2015_300000000.plot(column='gdp_capita_2015', figsize=(16, 12), legend = True, cmap='rocket', edgecolor="white");
df_2015_300000000.sort_values(by=['gdp_capita_2015']).head(10)
| Country Name | Country Code | geometry | 2015 | gdp_capita_2015 | gdp_2015 | |
|---|---|---|---|---|---|---|
| 93 | India | IND | POLYGON ((97.32711 28.26158, 97.40256 27.88254... | 1.310152e+09 | 1751.664429 | 2.294947e+12 |
| 134 | China | CHN | MULTIPOLYGON (((109.47521 18.19770, 108.65521 ... | 1.371220e+09 | 6500.281937 | 8.913317e+12 |
| 3 | United States | USA | MULTIPOLYGON (((-122.84000 49.00000, -120.0000... | 3.206352e+08 | 52116.738813 | 1.671046e+13 |
df_2015_300000000.sort_values(by=['gdp_capita_2015']).tail(10)
| Country Name | Country Code | geometry | 2015 | gdp_capita_2015 | gdp_2015 | |
|---|---|---|---|---|---|---|
| 93 | India | IND | POLYGON ((97.32711 28.26158, 97.40256 27.88254... | 1.310152e+09 | 1751.664429 | 2.294947e+12 |
| 134 | China | CHN | MULTIPOLYGON (((109.47521 18.19770, 108.65521 ... | 1.371220e+09 | 6500.281937 | 8.913317e+12 |
| 3 | United States | USA | MULTIPOLYGON (((-122.84000 49.00000, -120.0000... | 3.206352e+08 | 52116.738813 | 1.671046e+13 |
1.Only these three countries with population more than 300000000 according to 2015 data i.e 300 Million are shown 2.India and China have a much larger population than USA however the per capita GDP is too low for them
USA has higher GDP (52116.738813) and china is second (6500.281937) and last is India with 1751.664429
# Plotting Graphs from data frame
sns.catplot(x="Country Name", y=2015, kind="bar", data=df_2015_300000000, height=7, aspect=1, margin_titles = True)
# # Rotate x-labels
plt.xticks(rotation=-90)
(array([0, 1, 2]), <a list of 3 Text major ticklabel objects>)
df_2015_300000000.drop(['geometry'], axis = 1, inplace=True)
prof = ProfileReport(df_2015_300000000)
prof.to_file(output_file='df_2015_300000000.html')
/home/sarvesh/anaconda3/envs/geospatial/lib/python3.6/site-packages/pandas/core/frame.py:3997: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
# Geopanda Choropleth
# Plotting Graphs from data frame
df_2015_70000000.plot(column='gdp_capita_2015', figsize=(16, 12), legend = True, cmap='rocket', edgecolor="white");
df_2015_70000000.sort_values(by=['gdp_capita_2015']).head(10)
| Country Name | Country Code | geometry | 2015 | gdp_capita_2015 | gdp_2015 | |
|---|---|---|---|---|---|---|
| 129 | New Caledonia | NCL | POLYGON ((165.77999 -21.08000, 166.59999 -21.7... | 272400.0 | 0.000000 | 0.000000e+00 |
| 36 | Venezuela, RB | VEN | POLYGON ((-60.73357 5.20028, -60.60118 4.91810... | 30081829.0 | 0.000000 | 0.000000e+00 |
| 90 | Korea, Dem. Peopleâs Rep. | PRK | MULTIPOLYGON (((130.78000 42.22001, 130.78000 ... | 25183833.0 | 0.000000 | 0.000000e+00 |
| 103 | Syrian Arab Republic | SYR | POLYGON ((35.71992 32.70919, 35.70080 32.71601... | 17997408.0 | 0.000000 | 0.000000e+00 |
| 158 | Djibouti | DJI | POLYGON ((42.35156 12.54223, 42.77964 12.45542... | 913993.0 | 0.000000 | 0.000000e+00 |
| 11 | Somalia | SOM | POLYGON ((41.58513 -1.68325, 40.99300 -0.85829... | 13797201.0 | 0.000000 | 0.000000e+00 |
| 70 | Burundi | BDI | POLYGON ((30.46967 -2.41385, 30.52766 -2.80762... | 10160030.0 | 228.432544 | 2.320882e+09 |
| 61 | Central African Republic | CAF | POLYGON ((27.37423 5.23394, 27.04407 5.12785, ... | 4493170.0 | 346.693797 | 1.557754e+09 |
| 59 | Sierra Leone | SLE | POLYGON ((-13.24655 8.90305, -12.71196 9.34271... | 7171914.0 | 441.137664 | 3.163801e+09 |
| 73 | Madagascar | MDG | POLYGON ((49.54352 -12.46983, 49.80898 -12.895... | 24234088.0 | 469.942367 | 1.138862e+10 |
df_2015_70000000.sort_values(by=['gdp_capita_2015']).tail(10)
| Country Name | Country Code | geometry | 2015 | gdp_capita_2015 | gdp_2015 | |
|---|---|---|---|---|---|---|
| 2 | Canada | CAN | MULTIPOLYGON (((-122.84000 49.00000, -122.9742... | 35702908.0 | 50262.027666 | 1.794501e+12 |
| 125 | Netherlands | NLD | POLYGON ((6.90514 53.48216, 7.09205 53.14404, ... | 16939923.0 | 51871.576501 | 8.787005e+11 |
| 132 | Australia | AUS | MULTIPOLYGON (((147.68926 -40.80826, 148.28907... | 23815995.0 | 55079.892116 | 1.311782e+12 |
| 105 | Sweden | SWE | POLYGON ((11.02737 58.85615, 11.46827 59.43239... | 9799186.0 | 56339.994297 | 5.520861e+11 |
| 136 | Denmark | DNK | MULTIPOLYGON (((9.92191 54.98310, 9.28205 54.8... | 5683483.0 | 60402.129248 | 3.432945e+11 |
| 80 | Qatar | QAT | POLYGON ((50.81011 24.75474, 50.74391 25.48242... | 2565710.0 | 65137.057391 | 1.671228e+11 |
| 128 | Ireland | IRL | POLYGON ((-6.19788 53.86757, -6.03299 53.15316... | 4701957.0 | 65432.734445 | 3.076619e+11 |
| 122 | Switzerland | CHE | POLYGON ((9.59423 47.52506, 9.63293 47.34760, ... | 8282396.0 | 76553.282138 | 6.340446e+11 |
| 123 | Luxembourg | LUX | POLYGON ((6.04307 50.12805, 6.24275 49.90223, ... | 569604.0 | 107638.212260 | 6.131116e+10 |
| 148 | Eritrea | ERI | POLYGON ((36.42951 14.42211, 36.32322 14.82249... | 0.0 | NaN | 0.000000e+00 |
This shows countries with less than 70000000 population 2.Luxembourg,Switzerland,Ireland,Netherlands,Sweden and Qatar have a good GDP per Capita
This plot shows that a small population is scattered in large regions of worls whereas India and China have huge population
sns.catplot(x=2015, y="Country Name", kind="bar", data=df_2015_70000000, height=30, aspect=0.5, margin_titles = True)
# # Rotate x-labels
plt.xticks(rotation=-90)
/home/sarvesh/anaconda3/envs/geospatial/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py:214: RuntimeWarning: Glyph 128 missing from current font. /home/sarvesh/anaconda3/envs/geospatial/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py:214: RuntimeWarning: Glyph 153 missing from current font.
(array([ 0., 10000000., 20000000., 30000000., 40000000., 50000000.,
60000000., 70000000., 80000000.]),
<a list of 9 Text major ticklabel objects>)
/home/sarvesh/anaconda3/envs/geospatial/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py:183: RuntimeWarning: Glyph 128 missing from current font. /home/sarvesh/anaconda3/envs/geospatial/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py:183: RuntimeWarning: Glyph 153 missing from current font.
df_2015_70000000.drop(['geometry'], axis = 1, inplace=True)
# from pandas_profiling import ProfileReport
prof = ProfileReport(df_2015_70000000)
prof.to_file(output_file='df_2015_70000000.html')
/home/sarvesh/anaconda3/envs/geospatial/lib/python3.6/site-packages/pandas/core/frame.py:3997: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
# Geopanda Choropleth
# Plotting Graphs from data frame
df_2015_between.plot(column='gdp_capita_2015', figsize=(16, 12), legend = True, cmap='rocket', edgecolor="white");
df_2015_between.sort_values(by=['gdp_capita_2015']).head(10)
| Country Name | Country Code | geometry | 2015 | gdp_capita_2015 | gdp_2015 | |
|---|---|---|---|---|---|---|
| 93 | India | IND | POLYGON ((97.327 28.262, 97.403 27.883, 97.052... | 1.310152e+09 | 1751.664429 | 2.294947e+12 |
| 51 | Nigeria | NGA | POLYGON ((2.692 6.259, 2.749 7.871, 2.724 8.50... | 1.811374e+08 | 2563.148864 | 4.642822e+11 |
| 7 | Indonesia | IDN | MULTIPOLYGON (((141.000 -2.600, 141.017 -5.859... | 2.583833e+08 | 3824.274885 | 9.881286e+11 |
| 102 | Iran, Islamic Rep. | IRN | POLYGON ((48.568 29.927, 48.015 30.452, 48.005... | 7.849222e+07 | 6070.187284 | 4.764624e+11 |
| 134 | China | CHN | MULTIPOLYGON (((109.475 18.198, 108.655 18.508... | 1.371220e+09 | 6500.281937 | 8.913317e+12 |
| 23 | Mexico | MEX | POLYGON ((-117.128 32.535, -115.991 32.612, -1... | 1.218583e+08 | 10037.201490 | 1.223116e+12 |
| 8 | Argentina | ARG | MULTIPOLYGON (((-68.634 -52.636, -68.250 -53.1... | 4.313197e+07 | 10568.157809 | 4.558254e+11 |
| 25 | Brazil | BRA | POLYGON ((-53.374 -33.768, -53.651 -33.202, -5... | 2.044718e+08 | 11431.154481 | 2.337348e+12 |
| 17 | Russian Federation | RUS | MULTIPOLYGON (((178.725 71.099, 180.000 71.516... | 1.440969e+08 | 11537.202127 | 1.662475e+12 |
| 119 | Turkey | TUR | MULTIPOLYGON (((44.773 37.170, 44.293 37.002, ... | 7.852941e+07 | 13853.097134 | 1.087876e+12 |
India,Nigeria,Iran, Islamic Rep,China, mexico are some among the lowest
sns.catplot(x="Country Name", y='gdp_capita_2015', kind="bar", data=df_2015_between, height=7, aspect=2, margin_titles = True)
# Rotate x-labels
plt.xticks(rotation=-90)
(array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23]),
<a list of 24 Text major ticklabel objects>)
df_2015_between.drop(['geometry'], axis = 1, inplace=True)
prof = ProfileReport(df_2015_between)
prof.to_file(output_file='df_2015_between.html')
/home/sarvesh/anaconda3/envs/geospatial/lib/python3.6/site-packages/pandas/core/frame.py:3997: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
# Geopanda Choropleth
# Plotting Graphs from data frame
df_1995_2015_gdp.plot(column='mean_1995_2015', figsize=(16, 12), legend = True, cmap='rocket', edgecolor="white");
df_1995_2015_gdp.sort_values(by=['mean_1995_2015']).head(10)
| Country Name | Country Code | geometry | gdp_capita_1995 | gdp_capita_1996 | gdp_capita_1997 | gdp_capita_1998 | gdp_capita_1999 | gdp_capita_2000 | gdp_capita_2001 | ... | gdp_capita_2007 | gdp_capita_2008 | gdp_capita_2009 | gdp_capita_2010 | gdp_capita_2011 | gdp_capita_2012 | gdp_capita_2013 | gdp_capita_2014 | gdp_capita_2015 | mean_1995_2015 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 11 | Somalia | SOM | POLYGON ((41.58513 -1.68325, 40.99300 -0.85829... | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | ... | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 |
| 103 | Syrian Arab Republic | SYR | POLYGON ((35.71992 32.70919, 35.70080 32.71601... | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | ... | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 |
| 90 | Korea, Dem. Peopleâs Rep. | PRK | MULTIPOLYGON (((130.78000 42.22001, 130.78000 ... | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | ... | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 |
| 129 | New Caledonia | NCL | POLYGON ((165.77999 -21.08000, 166.59999 -21.7... | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | ... | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 |
| 158 | Djibouti | DJI | POLYGON ((42.35156 12.54223, 42.77964 12.45542... | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | ... | 0.000000 | 0.000000 | 0.000000 | 1343.268730 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 63.965178 |
| 70 | Burundi | BDI | POLYGON ((30.46967 -2.41385, 30.52766 -2.80762... | 262.375066 | 238.474632 | 232.305477 | 240.844573 | 235.309286 | 229.206107 | 228.660389 | ... | 225.859085 | 229.148545 | 230.192599 | 234.235647 | 235.988767 | 238.816046 | 242.845995 | 245.326739 | 228.432544 | 233.633446 |
| 157 | Ethiopia | ETH | POLYGON ((47.78942 8.00300, 44.96360 5.00162, ... | 183.547903 | 199.922992 | 200.026555 | 187.516734 | 191.571880 | 197.432305 | 207.752705 | ... | 273.492120 | 294.805428 | 312.033849 | 341.554115 | 369.202408 | 389.938967 | 419.183860 | 449.420377 | 482.639066 | 276.245885 |
| 98 | Afghanistan | AFG | POLYGON ((66.51861 37.36278, 67.07578 37.35614... | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | ... | 405.548979 | 412.014287 | 488.300251 | 543.303042 | 528.736648 | 576.190125 | 587.565090 | 583.656193 | 574.184114 | 306.124718 |
| 10 | Congo, Dem. Rep. | COD | POLYGON ((29.34000 -4.49998, 29.51999 -5.41998... | 401.185558 | 386.112866 | 355.528158 | 341.777825 | 319.562059 | 289.986320 | 276.142109 | ... | 315.263863 | 324.040313 | 322.418254 | 334.021573 | 345.266115 | 357.598296 | 375.219176 | 397.341670 | 411.020573 | 333.839489 |
| 59 | Sierra Leone | SLE | POLYGON ((-13.24655 8.90305, -12.71196 9.34271... | 315.935044 | 320.826792 | 300.394918 | 302.534249 | 291.170375 | 302.264266 | 272.991178 | ... | 375.668000 | 386.653814 | 390.131035 | 401.835001 | 417.603168 | 470.301405 | 555.205562 | 567.834267 | 441.137664 | 373.840007 |
10 rows × 25 columns
# temp_df = df_2015_300000000[['Country Name', 2015]]
sns.catplot(x='mean_1995_2015', y="Country Name", kind="bar", data=df_1995_2015_gdp, height=30, aspect=0.31,
margin_titles = True)
# # Rotate x-labels
plt.xticks(rotation=-90)
/home/sarvesh/anaconda3/envs/geospatial/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py:214: RuntimeWarning: Glyph 128 missing from current font. /home/sarvesh/anaconda3/envs/geospatial/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py:214: RuntimeWarning: Glyph 153 missing from current font.
(array([ 0., 20000., 40000., 60000., 80000., 100000., 120000.]), <a list of 7 Text major ticklabel objects>)
/home/sarvesh/anaconda3/envs/geospatial/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py:183: RuntimeWarning: Glyph 128 missing from current font. /home/sarvesh/anaconda3/envs/geospatial/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py:183: RuntimeWarning: Glyph 153 missing from current font.
1.This plot shows Mean of GDP per Capita from 1995 to 2015
2.Most of countries maintained a high GDP-per-capita from 1995
3.UAE have got a dark shade of blue as UAE gained it's economic growth very fast in the next decade
df_1995_2015_gdp.drop(['geometry'], axis = 1, inplace=True)
prof = ProfileReport(df_1995_2015_gdp)
prof.to_file(output_file='df_1995_2015_gdp.html')
# Geopanda Choropleth
# Plotting Graphs from data frame
df_pop_gdp_corr.plot(column='gdp_mean_1995_2015', figsize=(16, 12), legend = True, cmap='rocket', edgecolor="white");
This map shows the countries with their mean GDP per capita from 1995 to 2015
Most of the countries have maintained their GDP per Capita
While living standards have improved, the population have increased a lot
# Geopanda Choropleth
df_pop_gdp_corr.plot(column='pop_mean_1995_2015', figsize=(16, 12), legend = True, cmap='rocket', edgecolor="white");
df_pop_gdp_corr.sort_values(by=['pop_mean_1995_2015']).head(10)
| Country Name | Country Code | geometry | gdp_mean_1995_2015 | pop_mean_1995_2015 | |
|---|---|---|---|---|---|
| 19 | Greenland | GRL | POLYGON ((-46.76379 82.62796, -43.40644 83.225... | 37138.933459 | 56435.571429 |
| 84 | Vanuatu | VUT | MULTIPOLYGON (((167.21680 -15.89185, 167.84488... | 2765.947720 | 212540.047619 |
| 129 | New Caledonia | NCL | POLYGON ((165.77999 -21.08000, 166.59999 -21.7... | 0.000000 | 232215.761905 |
| 35 | Belize | BLZ | POLYGON ((-89.14308 17.80832, -89.15091 17.955... | 4032.345500 | 284212.904762 |
| 138 | Iceland | ISL | POLYGON ((-14.50870 66.45589, -14.73964 65.808... | 40950.450346 | 299141.047619 |
| 18 | Bahamas, The | BHS | MULTIPOLYGON (((-78.98000 26.79000, -78.51000 ... | 29620.691606 | 326343.190476 |
| 143 | Brunei Darussalam | BRN | POLYGON ((115.45071 5.44773, 115.40570 4.95523... | 35985.575230 | 360754.476190 |
| 130 | Solomon Islands | SLB | MULTIPOLYGON (((162.11902 -10.48272, 162.39865... | 1347.049634 | 472729.571429 |
| 123 | Luxembourg | LUX | POLYGON ((6.04307 50.12805, 6.24275 49.90223, ... | 97061.702685 | 474330.952381 |
| 38 | Suriname | SUR | POLYGON ((-54.52475 2.31185, -55.09759 2.52375... | 7071.201904 | 500107.666667 |
fig = px.scatter(df_pop_gdp_corr, x="pop_mean_1995_2015", y="gdp_mean_1995_2015", color="Country Name")
fig.show()
fig = px.scatter_matrix(df_pop_gdp_corr, dimensions=["pop_mean_1995_2015", "gdp_mean_1995_2015"], color="Country Name")
fig.show()
fig = px.scatter(df_pop_gdp_corr, x="pop_mean_1995_2015", y="gdp_mean_1995_2015", size="gdp_mean_1995_2015", color="Country Name",
hover_name="Country Name", log_x=True, size_max=30)
fig.show()
# Mean GDP VS Country Name
sns.catplot(x='gdp_mean_1995_2015', y="Country Name", kind="bar", data=df_pop_gdp_corr, height=30, aspect=0.31, margin_titles = True)
# # Rotate x-labels
plt.xticks(rotation=-90)
/home/sarvesh/anaconda3/envs/geospatial/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py:214: RuntimeWarning: Glyph 128 missing from current font. /home/sarvesh/anaconda3/envs/geospatial/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py:214: RuntimeWarning: Glyph 153 missing from current font.
(array([ 0., 20000., 40000., 60000., 80000., 100000., 120000.]), <a list of 7 Text major ticklabel objects>)
/home/sarvesh/anaconda3/envs/geospatial/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py:183: RuntimeWarning: Glyph 128 missing from current font. /home/sarvesh/anaconda3/envs/geospatial/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py:183: RuntimeWarning: Glyph 153 missing from current font.
# Mean Population VS Country Name
sns.catplot(x='pop_mean_1995_2015', y="Country Name", kind="bar", data=df_pop_gdp_corr, height=30, aspect=0.31, margin_titles = True)
# # Rotate x-labels
plt.xticks(rotation=-90)
(array([0.0e+00, 2.0e+08, 4.0e+08, 6.0e+08, 8.0e+08, 1.0e+09, 1.2e+09,
1.4e+09]),
<a list of 8 Text major ticklabel objects>)
df_pop_gdp_corr.drop(['geometry'], axis = 1, inplace=True)
prof = ProfileReport(df_pop_gdp_corr)
prof.to_file(output_file='df_pop_gdp_corr.html')
sns.pairplot(df_pop_gdp_corr, markers=["o"], diag_kind="hist")
<seaborn.axisgrid.PairGrid at 0x7f0afce19d30>
# The is the correlation plot of mean population and mean gdp per capita
sns.pairplot(df_pop_gdp_corr, markers=["o"], diag_kind="kde")
<seaborn.axisgrid.PairGrid at 0x7f0b10b4ab00>
sns.relplot(x="pop_mean_1995_2015", y="gdp_mean_1995_2015", hue="Country Name", data=df_pop_gdp_corr);
/home/sarvesh/anaconda3/envs/geospatial/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py:214: RuntimeWarning: Glyph 128 missing from current font. /home/sarvesh/anaconda3/envs/geospatial/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py:214: RuntimeWarning: Glyph 153 missing from current font. /home/sarvesh/anaconda3/envs/geospatial/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py:183: RuntimeWarning: Glyph 128 missing from current font. /home/sarvesh/anaconda3/envs/geospatial/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py:183: RuntimeWarning: Glyph 153 missing from current font.
correlation = df_pop_gdp_corr.corr(method='kendall')
correlation
| gdp_mean_1995_2015 | pop_mean_1995_2015 | |
|---|---|---|
| gdp_mean_1995_2015 | 1.000000 | -0.067903 |
| pop_mean_1995_2015 | -0.067903 | 1.000000 |
sns.heatmap(correlation)
<matplotlib.axes._subplots.AxesSubplot at 0x7f0b109149e8>
Goal: In this task, I am applying sentiment analysis to Twitter data using the Python libraries TextBlob and Tweepy
Import external libraries (thus verifying they are correctly installed)
import os
import json
import time
import csv
import re # Regular Expression Python module
import pandas as pd #Data manipulation and analysis library
import numpy as np # mathematical functions on multi-dimensional arrays and matrices
import matplotlib.pyplot as plt # plotting library to create graphs and charts
import tweepy as tw #Python library for accessing the Twitter API.
from textblob import TextBlob # Python library for processing textual data
from wordcloud import WordCloud #WordCloud - Python linrary for creating image wordclouds
import tweepy
# Settings for Matplotlib graphs and charts
from pylab import rcParams
rcParams['figure.figsize'] = 12, 8
%matplotlib inline
pd.options.display.max_colwidth = 100
pd.options.display.precision = 3
Recent tweets matching a given query can be searched using the Twitter Search API; many libraries exist for Python. We see here how to obtain tweets using the TwitterSearch package, installable with pip install TwitterSearch; a Twitter account with an associated mobile number is needed in order to use the API
In order to use Twitter APIs you need API keys: follow these steps to obtain one
You will need strings labeled with Consumer Key, Consumer Secret, Access Token and Access Token Secret shown in the page to use the API
#consumer key, consumer secret, access token, access secret.
consumer_key="IQKbtAYlXLripLGPWd0HUA"
consumer_secret="Bcs59EFbbsdF6Sl9Ng71smgStWEGwXXKSjYvPVt7qys"
access_token="NPcudxy0yU5T3tBzho7iCotZ3cnetKwcTIRlX0iwRl0"
access_token_secret="veNRnAWe6inFuo8o2u8SLLZLjolYDmDP7SzL0YfYI"
Import the necessary classes and create a TwitterSearch object providing the API codes obtained above
# Create the authentication object
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
# Set the access token and access token secret
auth.set_access_token(access_token, access_token_secret)
# Set the access token and access token secret
api = tweepy.API(auth,wait_on_rate_limit=True)
Twittersearch_word = '#lockdown'
date_since = '2020-12-01'
#creating a tweepy itemiterator tweets for searching by calling tw.Cursor func, pulling only 600 records
tweets = tw.Cursor(api.search,q = search_word, lang ='en',since = date_since).items(600)
# get geo = where its tweeted from, location = user location etc.
tweet_details = [[tweet.text]for tweet in tweets]
tweet_df = pd.DataFrame(data = tweet_details,columns=['text'])
pd.set_option('max_colwidth',800)
tweet_df.head(20)
tweet_df.to_csv('Twitter.csv', index=False)
df=pd.read_csv('Twitter.csv')
df.head()
| text | |
|---|---|
| 0 | Aren't the Germans supposed to send #MercedesBenz?\n#BrexitShambles #lockdown\nhttps://t.co/jo3k... |
| 1 | @haunted_mars @iaindwelch Did you find anything?😟🎄🎅🎄\nGot a bed and bananas for Mickey\nBut it's... |
| 2 | RT @MaximeBernier: Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you an... |
| 3 | RT @MaximeBernier: Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you an... |
| 4 | Any MPs who dither about #lockdown should have the whip withdrawn #bbcpm #skynews |
# Create a function to clean the tweets
import re
def cleanTxt(txt):
# Remove mentions
txt = re.sub(r'@[A-Za-z0-9_]+', '', txt)
# Remove hashtags
txt = re.sub(r'#', '', txt)
# Remove retweets:
txt = re.sub(r'RT : ', '', txt)
# Remove urls
txt = re.sub(r'https?:\/\/[A-Za-z0-9\.\/]+', '', txt)
txt = re.sub(r'\n', '', txt)
return txt
# Clean the tweets
df['text'] = df['text'].apply(cleanTxt)
# Show
df.head()
| text | |
|---|---|
| 0 | Aren't the Germans supposed to send MercedesBenz?BrexitShambles lockdown |
| 1 | Did you find anything?😟🎄🎅🎄Got a bed and bananas for MickeyBut it's slim pickings Ready… |
| 2 | Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are tol... |
| 3 | Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are tol... |
| 4 | Any MPs who dither about lockdown should have the whip withdrawn bbcpm skynews |
We have some empty rows here so before further processing let's remove those.
The below command will remove all the rows with the Tweet column equals to "".
df = df.drop(df[df['text'] == ''].index)
# Create a function to get the subjectivity
import textblob
def getSubjectivity(text):
return TextBlob(text).sentiment.subjectivity
# Create a function to get the polarity
def getPolarity(text):
return TextBlob(text).sentiment.polarity
# Create two new columns 'Subjectivity' & 'Polarity'
df['Subjectivity'] = df['text'].apply(getSubjectivity)
df['Polarity'] = df['text'].apply(getPolarity)
# Show the new dataframe with columns 'Subjectivity' & 'Polarity'
df.head()
| text | Subjectivity | Polarity | |
|---|---|---|---|
| 0 | Aren't the Germans supposed to send MercedesBenz?BrexitShambles lockdown | 0.000 | 0.000 |
| 1 | Did you find anything?😟🎄🎅🎄Got a bed and bananas for MickeyBut it's slim pickings Ready… | 0.000 | 0.000 |
| 2 | Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are tol... | 0.688 | -0.312 |
| 3 | Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are tol... | 0.688 | -0.312 |
| 4 | Any MPs who dither about lockdown should have the whip withdrawn bbcpm skynews | 0.000 | 0.000 |
# word cloud visualization
allWords = ' '.join([twts for twts in df['text']])
wordCloud = WordCloud(width=500, height=500, random_state=21, max_font_size=110).generate(allWords)
plt.imshow(wordCloud, interpolation="bilinear")
plt.axis('off')
plt.show()
ax = df['Polarity'].plot.hist(bins=12, alpha=0.5)
plt.title('Polarity Histogram')
plt.xlabel('Polarity')
plt.ylabel('Frequency')
# add legend
plt.show()
We can see that we have a calculated score for the subjectivity and polarity in our data frame.
Now let's build a function and categorize our tweets as Negative, Neutral and Positive.
# Create a function to compute negative (-1), neutral (0) and positive (+1) analysis
def getAnalysis(score):
if score < 0:
return 'Negative'
elif score == 0:
return 'Neutral'
else:
return 'Positive'
df['Analysis'] = df['Polarity'].apply(getAnalysis)
# Show the dataframe
df.head()
| text | Subjectivity | Polarity | Analysis | |
|---|---|---|---|---|
| 0 | Aren't the Germans supposed to send MercedesBenz?BrexitShambles lockdown | 0.000 | 0.000 | Neutral |
| 1 | Did you find anything?😟🎄🎅🎄Got a bed and bananas for MickeyBut it's slim pickings Ready… | 0.000 | 0.000 | Neutral |
| 2 | Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are tol... | 0.688 | -0.312 | Negative |
| 3 | Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are tol... | 0.688 | -0.312 | Negative |
| 4 | Any MPs who dither about lockdown should have the whip withdrawn bbcpm skynews | 0.000 | 0.000 | Neutral |
And apply this function and create another feature in our data frame called Score.
# Printing positive tweets
print('Printing positive tweets:\n')
j=1
sortedDF = df.sort_values(by=['Polarity']) #Sort the tweets
for i in range(0, sortedDF.shape[0] ):
if( sortedDF['Analysis'][i] == 'Positive'):
print(str(j) + ') '+ sortedDF['text'][i])
print()
j= j+1
Printing positive tweets: 1) Two films for lockdown for today. Both on BBCTWO, Casablanca (1942), 2:15pm; need I say more: … 2) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 3) The top 10 MPs were identified based on field interviews and feedback from the respective constituencies. RahulGandhi COVI… 4) The right thing to do would be to resign, deaths of this proportion are unacceptable and as far as the public can s… 5) Lux!23 Decembre▪️luxe like23decembre axenn adventureculture love noel chritmas cov… 6) Live London Tier 4 updates as Matt Hancock to hold Downing Street press conference amid reports of a new national… 7) Coronavirus I said nearly a year ago (january): believe what you want about Covid_19. But don't underweight the danger.… 8) Air Pollution killed 10 TIMES more people in India 2019 than COVID-19 did in all of 2020. 1.96 Million died from air polluti… 9) Buckle down folks and get ready for todays comedy special with the totally incompetent Twatty Wanksock covidbriefing Covid19 Lockdown 10) Air Pollution killed 10 TIMES more people in India 2019 than COVID-19 did in all of 2020. 1.96 Million died from air polluti… 11) Merry X-Mas to all of you and thank you so much for your music 🙏😊.❄🌟🎁🎄💫🎅🏼🌟❄… 12) Mr among the Most Helpful MPs during LockdownWell! I am not surprised because he is a man of Hard-work, the voi… 13) Heathrow & Dover The NEW ABNORMAL / Hugo Talks lockdown via Trump/Pence 2020! Don Jr 2024! 14) Breaking News: The whole of Cornwall has been placed into tier 4 lockdown after hundreds of pirates returned home to Pen… 15) Happy Birthday to my fellow Spurs fan and Christmas baby Oh & welcome to that not so exclusive ‘Co… 16) Air Pollution killed 10 TIMES more people in India 2019 than COVID-19 did in all of 2020. 1.96 Million died from air polluti… 17) India needs more testing....unlock1point0 will might be dangerous.....lockdown should be extend....PMOfIndia … 18) 'Demands' or 'urges'. One things for sure, you'll never get away with pushing ImmunityPassports onto pe… 19) Is anyone else excited and hopeful for a Normal New Year instead of a New Normal Year? NewNormal COVID19 COVIDSecondWave lockdown mask 20) How many lockdowns can we expect in 2021 ?Lockdown3 lockdown COVID19 COVID20 WearYourMask 21) Mr among the Most Helpful MPs during LockdownWell! I am not surprised because he is a man of Hard-work, the voi… 22) Mr among the Most Helpful MPs during LockdownWell! I am not surprised because he is a man of Hard-work, the voi… 23) So it's true they never isolated the virus... Not a conspiracy the measure in place are disproportionate there is no St… 24) Ontario is going into lockdown for a month as of boxing Day and will lose my babysitter. I don't know exactly how t… 25) Eventually, with too much lockdown, people will realise that money is also needed for healthcare.1. Lockdown2.… 26) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 27) ASPHER President is 'Planning for an Outbreak of Health', but first we must muddle through this Christmas s… 28) Check out my latest video "Devils Ivy Propagation in Water !!!"Watch Now: Pothos… 29) Something creative and sustainable for lockdown festivities! 30) Having a Covid19 discussion with a 78 year old man and his exact words:"It is getting like a SciFi movie; someth… 31) Still think it’s just a flu? We can be grateful that during the first we were able to FlattenTheCurve sadly we ar… 32) Lockdown, Christmas and ecommerce: is Europe really destined to become Amazon’s warehouse worker? - Andrea Di Cam… 33) Mr among the Most Helpful MPs during LockdownWell! I am not surprised because he is a man of Hard-work, the voi… 34) Is business growth all you want for Christmas? Fergus explores his top tips on how to approach new clients during l… 35) With the announcment of the new provincial lockdown starting Dec 26, 2020, we wanted to give you a heads up on how we… 36) 1. Many prisoners have no access to family visits right now because of lockdown responses to Covid19. Other support… 37) Christmas gifts of scintillating conversation & soulful songs by charismatic Cypriot Londoners DonnaAndK… 38) Mr among the Most Helpful MPs during LockdownWell! I am not surprised because he is a man of Hard-work, the… 39) 1. Many prisoners have no access to family visits right now because of lockdown responses to Covid19. Other support… 40) Here is a new clip from our third tutorial video. The coaches explain how to generate power with the lead hand… 41) Christmas gifts of scintillating conversation & soulful songs by charismatic Cypriot Londoners DonnaAndK… 42) Investors will be continuing to watch coronavirus statistics & lockdown measures as the latest surge in cases & hos… 43) Here is a new clip from our third tutorial video. The coaches explain how to generate power with the lead hand… 44) Shri Ji among the Most Helpful MPs during lockdown Well! I am not surprised because he is a man of Hard-wor… 45) Christmas gifts of scintillating conversation & soulful songs by charismatic Cypriot Londoners … 46) Two days before Christmas — these cnuts really are taking the p*ss.How much more of this are we going to take, fo… 47) A reasonable question | Lockdown shutdown Illinois Chicago politics 48) ACCURATE TAROT PREDICTIONS ABOUT COVIDSecondWave VIDEO POSTED ON 7TH MAY. Watch the full video.… 49) Thanks for supporting this Christmas Lockdown😃👍 50) Shri Ji among the Most Helpful MPs during lockdown Well! I am not surprised because he is a man of Hard-wor… 51) Hello,are you looking for a graphicde_signer? I will design amazing business_cards, letterhead and stationery… 52) New Bond Street london🇬🇧 LondonLockdown LondonDay 倫敦 لندن KeepMoving Lockdown ロンドン OutInLondon… 53) The Uk’s Covid 19 Genomics Consortium hasn’t seen any data at all on transmission being more infectious in Children.… 54) With the announcment of the new provincial lockdown starting Dec 26, 2020, we wanted to give you a heads up on how we… 55) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 56) Good morning everyone! What are you doing today? lockdown 57) Meet this youngster from Pune who is a marketing trainer for the disabled, wants to reach out to more people and is… 58) VIRUSEND has been issued to service personnel. It will be used to decontaminate frequently touched surfaces. Eliminates Cor… 59) Nice to hear someone supporting RoyalMail for a change👍 No matter what Tier you are in… 60) Mr among the Most Helpful MPs during LockdownWell! I am not surprised because he is a man of Hard-work, the voi… 61) Mr among the Most Helpful MPs during LockdownWell! I am not surprised because he is a man of Hard-work, the voi… 62) Mr among the Most Helpful MPs during LockdownWell! I am not surprised because he is a man of Hard-work, the voi… 63) Last day of our specialPlace challenge. A new Christmas lockdown challenge will be posted later today. staysafe 64) 'Arnopp's Tudor books have kept me enthralled through lock down. I would recommend them to anyone interested in Tudor hi… 65) We need to use proper masks...face shields, cotton masks, homemade masks, bandanas etc. do absolutely nothing and put every… 66) Air Pollution killed 10 TIMES more people in India 2019 than COVID-19 did in all of 2020. 1.96 Million died from air polluti… 67) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 68) Some Great Shots✊🏾They Look Jus Like The World Leaders & PoopHoles Who Have Created This C19 PLANNED Virus… 69) Mr among the Most Helpful MPs during LockdownWell! I am not surprised because he is a man of Hard-work, the voi… 70) The top 10 MPs were identified based on field interviews and feedback from the respective constituencies. RahulGandhi COVI… 71) covid19 Brave yourself UK more bad news coming down the pipe at around 3 pm today. Mind you Boris does not have a… 72) Escape to another realm this lockdown with the Storm Trilogy.Thrilling fantasy adventure for an epic price.Get all 3… 73) The unemployment numbers are going back up. There are more people who are being sensible by adhering to lockdown… 74) Pharma sector revenue, margins likely to remain healthy in FY2022: ICRA - Window To News ICRA,Covid,lockdown 75) Watching the news sources and I'm more convinced than ever that the government are delaying the lockdown announcem… 76) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 77) Absolute retardation! Let's wait until the DAY AFTER the day known for the most gatherings during the year! I… 78) Happy Hump Day.Check out our special offers at And sign up to our newletter for specila ex… 79) Happy Hump Day.Check out our special offers at And sign up to our newletter for specila ex… 80) WATCH INSIDE OUT: SEASON 2 NOW6 FREE short episodes continuing the stories begun during the summer; funny, imagin… 81) Since business owners can put a price on everything, I really wish they would put a price on how many lives are accept… 82) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 83) The UK might be back in lockdown, but that doesn't stop us from continuing to learn and daydream!Explore the top 30+ Ir… 84) Mr among the Most Helpful MPs during LockdownWell! I am not surprised because he is a man of Hard-work… 85) Mr among the Most Helpful MPs during LockdownWell! I am not surprised because he is a man of Hard-w… 86) Send me ur photo n I’ll return a sketch within 24 hours. All 4 free! covid19 lockdown art sketch bhutan 87) Mr among the Most Helpful MPs during LockdownWell! I am not surprised because he is a man of Hard-work, the voi… 88) Good afternoon 🤩Morning here🤩Hope you have a splendid day 🤩Due for a storm 🤩lockdown Christmas day and 28 days… 89) ShutDownIranTerrorEmbassies is more urgent than lockdown to protect ppl against Covid_19 .… 90) Mask in the car wearer. Real stable genius. Masks lockdown California NewYork 91) ShutDownIranTerrorEmbassies is more urgent than lockdown to protect ppl against Covid_19 .… 92) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 93) 'Arnopp's Tudor books have kept me enthralled through lock down. I would recommend them to anyone interested in Tudor hi… 94) 1. Many prisoners have no access to family visits right now because of lockdown responses to Covid19. Other support… 95) Since business owners can put a price on everything, I really wish they would put a price on how many lives are accept… 96) NEW Improved 2 Finger holes for better strength and stability COVID Door Opener Numerous Colours… 97) Can you spare 15 minutes to complete a survey to help increase our understanding of how coronavirus and the… 98) Didn't get a chance to wear the ChristmasJumper on ChristmasJumperDay as I was off, so here it is! Kind of sums up loc… 99) How can you provide top quality materials for home learning without working 12 hours a day to do it?… 100) Mr among the Most Helpful MPs during LockdownWell! I am not surprised because he is a man of Hard-work, the voi… 101) innovative mealkits have served as a revenue stream for restaurants during lockdown. Why not give customers… 102) Mr among the Most Helpful MPs during LockdownWell! I am not surprised because he is a man of Hard-work, the voi… 103) We asked our team what kept them going during lockdown. Our first ‘lockdown love’ is a book about the Japanese videogam… 104) We asked our team what kept them going during lockdown. Our second ‘lockdown love’ is a book by Susan Cain about of the… 105) We asked our team what kept them going during lockdown. Our third ‘lockdown love’ is a record by Bring me the Horizon c… 106) We asked our team what kept them going during lockdown. Our fourth ‘lockdown love’ is an online workout from Les Mills… 107) We asked our team what kept them going during lockdown. Our fifth ‘lockdown love’ is the classic TV series Friends - ht… 108) Tiers don’t mean anything. Only today I’ve seen many people entering tier4 two of whom have gotten over cancer bef… 109) [Thread] Great visualisation by of the daily confirmed COVID19SA cases since March and how the number of cases c… 110) California lockdown is clearly working well. coronavirus California 111) This should be Christmas and New year number 1 lockdown aliceDJ 112) Live from the Euro Tunnel...brexit euro lockdown 113) Since business owners can put a price on everything, I really wish they would put a price on how many lives are accept… 114) ➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & dependency on govt➡️Da… 115) Mr among the Most Helpful MPs during LockdownWell! I am not surprised because he is a man of Hard-work, the voi… 116) Sorry for not making this my first tweet. Happy Festivus! And now for the feats of strength. lockdown ends… 117) Since business owners can put a price on everything, I really wish they would put a price on how many lives are acc… 118) According to BookMyShow's ShowOfTheYear2020 analysis, Christopher Nolan's Tenet became the most seen movie in Indi… 119) During a lockdown, it is easy to feel enveloped in general anxiety. For cancersurvivors, the sense of disorienta… 120) Didn't get a chance to wear the ChristmasJumper on ChristmasJumperDay as I was off, so here it is! Kind of sums… 121) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 122) 'Tenet' most watched film in India post lockdown - Window To News Mumbai,Lockdown,Chennai 123) Bournemouth group is rapidly growing well done everyone supporting local groups. We do not consent to lockdowns, covid19 vax… 124) My new recipe for lockdown 2.0Mung beans (salbuko ~in Somali), fried in red 🌶, broccoli 🥦 , red onion 🌰 & garnished wi… 125) 'Arnopp's Tudor books have kept me enthralled through lock down. I would recommend them to anyone interested in Tudor hi… 126) lockdown christmascake Everyone we'd like to spend Christmas with but can't❤. Even more relevant now that my son… 127) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 128) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 129) Air Pollution killed 10 TIMES more people in India 2019 than COVID-19 did in all of 2020. 1.96 Million died from air polluti… 130) O Corona...wapis jao...A hindi song inspired by the very famous Bella Ciao!⬇️… 131) Sorry for not making this my first tweet. Happy Festivus! And now for the feats of strength. lockdown… 132) Oh ..... we’ll miss you this year.... so we made this song for you..... Link to full tune in bio 🎅🏼… 133) Full national lockdown from BoxingDay mooted at GovernmentGoldCommand meeting 134) Live natural life.AbolishTheDeathPenalty LawOfAtrraction BrandonBernard HumanRightsDay Brandon CrashLandingONEYou SS… 135) My new recipe for lockdown 2.0Mung beans (salbuko ~in Somali), fried in red 🌶, broccoli 🥦 , red onion 🌰 & garnished wi… 136) Someone very clever once said "Insanity: doing the same thing over and over again and expecting different results"… 137) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 138) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 139) Covid R number may be as high as 1.5 in London and the South East as fears mount that more areas of England will b… 140) I do magic over my facebook feed. As soon as I refresh it, people get married. 🥳🌿 2020InReview Facebook lockdown ImReallyBlack 141) You haven't seen the iconic movie Coming to America? How dare you? 🙄😂 No excuse lockdown. It's been pla… 142) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 143) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 144) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 145) Live natural life.AbolishTheDeathPenalty LawOfAtrraction BrandonBernard HumanRightsDay Brandon CrashLandingONEYou SS… 146) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 147) Live natural life.AbolishTheDeathPenalty LawOfAtrraction BrandonBernard HumanRightsDay Brandon CrashLandingONEYou SS… 148) Merry X-Mas to all of you and thank you so much for your music 🙏😊.❄🌟🎁🎄💫🎅🏼🌟❄… 149) Now I’m at the stunning about to watch The Muppet Christmas Carol (1992). During lockdown the cinema… 150) Don't let the lockdown get you down. Even if you can't visit your favourite restaurant, you can order in and Deft Run will d… 151) Good morning y’all 😍 please when if appears on your timeline retweet 🤲..danla December21st lockdown Werner leumastech… 152) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 153) This is BakeOff Sheen. He is on the Showbiz career path but he has a Cooking Hobby and an aspiration to win a Cooking… 154) What's new in 2020 2021?A brand new online collection sales corner 🤩🤩🤩🎄🎄🎄Sales Swiss… 155) Live natural life.AbolishTheDeathPenalty LawOfAtrraction BrandonBernard HumanRightsDay Brandon CrashLandingONEYou SS… 156) Professor calls for full national lockdown today to stop England being 'on fire' All this was avoidable With Anti lockdown… 157) Here is the IPOs picture for Year2020 Interesting is Before lockdown we have Only SBICreditCard But Real Money m… 158) The Western Cape High Court in SouthAfrica has ruled that the cigarette sales ban during the country's hard… 159) Our very own Phil 'Swill' Odgers play a full set of The Men They Couldn't Hang songs this evening at 8PM GMT on Facebook: h… 160) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 161) Live natural life.AbolishTheDeathPenalty LawOfAtrraction BrandonBernard HumanRightsDay Brandon CrashLandingONEYou SS… 162) Air Pollution killed 10 TIMES more people in India 2019 than COVID-19 did in all of 2020. 1.96 Million died from air polluti… 163) Live natural life.AbolishTheDeathPenalty LawOfAtrraction BrandonBernard HumanRightsDay Brandon… 164) Air Pollution killed 10 TIMES more people in India 2019 than COVID-19 did in all of 2020. 1.96 Million died from air polluti… 165) With the announcment of the new provincial lockdown starting Dec 26, 2020, we wanted to give you a heads up on how we… 166) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 167) Air Pollution killed 10 TIMES more people in India 2019 than COVID-19 did in all of 2020. 1.96 Million died from air polluti… 168) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 169) Air Pollution killed 10 TIMES more people in India 2019 than COVID-19 did in all of 2020. 1.96 Million died from air polluti… 170) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 171) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 172) The top 10 MPs were identified based on field interviews and feedback from the respective constituencies. RahulGandhi COVI… 173) The real perpetrators of this whole thing enjoy your suffering, they have many aims, one of the main ones is killing Y… 174) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 175) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 176) Our very own Phil 'Swill' Odgers play a full set of The Men They Couldn't Hang songs this evening at 8PM GMT on Facebook: h… 177) Our very own Phil 'Swill' Odgers play a full set of The Men They Couldn't Hang songs this evening at 8PM GMT on Facebook: h… 178) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 179) With the announcment of the new provincial lockdown starting Dec 26, 2020, we wanted to give you a heads up on how we… 180) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 181) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 182) who thought that aroma therapy would have that relaxing effect on me¿ living my 60s rn thanks to the lockdown 183) Why the West is failing to control COVID19Ontario premier announced a full lockdown yesterday that wi… 184) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 185) Well, just once in a while 🙂! And probably little more during lockdown 😁break life happinessisaplace beer… 186) With the Netherlands and Germany now in hard lockdown we see a spike in downloads of our newest publication. Enjoy ‘Hom… 187) COVID19: Anarchy in times of pandemic - A pamphlet By Gustavo Rodriguez - Translated by - Read more: https:/… 188) During lockdown the main way to recruit new team members is via video, but it's not always an easy skill to pick u… 189) There is the magic of Christmas and there is the magic of Mariateresa Carletti italian fashiondesigner… 190) Air Pollution killed 10 TIMES more people in India 2019 than COVID-19 did in all of 2020. 1.96 Million died from air polluti… 191) proactively e-enable high standards in quality vectors with domains 💰 Buy domain covid lockdown… 192) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 193) With the announcment of the new provincial lockdown starting Dec 26, 2020, we wanted to give you a heads up on how we… 194) Air Pollution killed 10 TIMES more people in India 2019 than COVID-19 did in all of 2020. 1.96 Million died from air polluti… 195) Shri Ji among the Most Helpful MPs during lockdown Well! I am not surprised because he is a man of Hard-wor… 196) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 197) Good morning from Vienna ☁️ ☕️ 🇦🇹 Views of the Danube Canal and the Urania complex (1910) on the famous Ringstraße in th… 198) The top 10 MPs were identified based on field interviews and feedback from the respective constituencies. RahulGandhi COVI… 199) Air Pollution killed 10 TIMES more people in India 2019 than COVID-19 did in all of 2020. 1.96 Million died from air polluti… 200) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 201) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 202) Mr among the Most Helpful MPs during LockdownWell! I am not surprised because he is a man of Hard-work, the voi… 203) Not a COVID19 panicbuying item, but our lass did want to make sure if there is another lockdown we had enough compost.… 204) Not a COVID19 panicbuying item, but our lass did want to make sure if there is another lockdown we had enough compost.… 205) Air Pollution killed 10 TIMES more people in India 2019 than COVID-19 did in all of 2020. 1.96 Million died from air polluti… 206) Mr among the Most Helpful MPs during LockdownWell! I am not surprised because he is a man of Hard-work, the voi… 207) Air Pollution killed 10 TIMES more people in India 2019 than COVID-19 did in all of 2020. 1.96 Million died from air polluti… 208) Now I’m at the stunning about to watch The Muppet Christmas Carol (1992). During lockdown the cine… 209) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 210) With the announcment of the new provincial lockdown starting Dec 26, 2020, we wanted to give you a heads up on how we… 211) Our very own Phil 'Swill' Odgers play a full set of The Men They Couldn't Hang songs this evening at 8PM GMT on Facebook: h… 212) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 213) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 214) The top 10 MPs were identified based on field interviews and feedback from the respective constituencies. RahulGandhi COVI… 215) Mr among the Most Helpful MPs during LockdownWell! I am not surprised because he is a man of Hard-work, the voi… 216) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 217) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 218) We added 26 slot providers so you have something fun to do during this Christmas lockdown🦠🤣▶️… 219) Bournemouth group is rapidly growing well done everyone supporting local groups. We do not consent to lockdowns, covid19 vax… 220) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 221) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 222) What to do when in lockdown? Playing with Workers, JestJS and seems like an excellent idea! https:/… 223) Wise words from the Christkindl "I believe that this year is different, that we have to get used to doing things diffe… 224) Medals achieved since the first ever lockdown until now. 🙂5k 10ks halfmarathons Marathons runner ukrunchat fit… 225) The top 10 MPs were identified based on field interviews and feedback from the respective constituencies.… 226) Mr among the Most Helpful MPs during LockdownWell! I am not surprised because he is a man of Hard-work, the voi… 227) Sikh community steps up and prepares hundreds of free meals for stranded lorry drivers at ManstonAirport… 228) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 229) Air Pollution killed 10 TIMES more people in India 2019 than COVID-19 did in all of 2020. 1.96 Million died from air polluti… 230) We added 26 slot providers so you have something fun to do during this Christmas lockdown🦠🤣▶️… 231) We added 26 slot providers so you have something fun to do during this Christmas… 232) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 233) Air Pollution killed 10 TIMES more people in India 2019 than COVID-19 did in all of 2020. 1.96 Million died from air polluti… 234) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 235) Want to give a shout-out to posties drivers supermarket workers who have worked right through lockdown it’s much appreciated 👏🏻👏🏻👏🏻 236) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 237) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 238) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 239) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & depend… 240) What's open and what's closed under the new covid19 lockdown? Check it out here. pandemic2020 241) LIVE today 9am EASTERN➡️Trump: $2,000 StimulusChecks— more free stuff, but NO FREEDOMperpetuating lockdown & d… 242) This is Xmas messages from some of the people we care for during the lockdown, it's very touching... 💞lockdownFoodhub… 243) Mr among the Most Helpful MPs during LockdownWell! I am not surprised because he is a man of Hard-work, the voi… 244) Mr among the Most Helpful MPs during LockdownWell! I am not surprised because he is a man of Hard-work, the voi… 245) Our very own Phil 'Swill' Odgers play a full set of The Men They Couldn't Hang songs this evening at 8PM GMT on Fac… 246) With the announcment of the new provincial lockdown starting Dec 26, 2020, we wanted to give you a heads up on how we… 247) Have I told you about my new band?We're called Tiers 4 Fearslockdown tier4 248) Going online later! Come sing? Come jive? Let's just have some fun =) TwitchAffilate… 249) With the announcment of the new provincial lockdown starting Dec 26, 2020, we wanted to give you a heads up on how we… 250) Here is the IPOs picture for Year2020 Interesting is Before lockdown we have Only SBICreditCard But Real Money m… 251) Some great birds on a lockdown birding walk from home please see new blog here 252) With the announcment of the new provincial lockdown starting Dec 26, 2020, we wanted to give you a heads up on how we… 253) Like so many things in 2020, 'Last Minute Shopping' has taken on a whole different connotation as we are moving into … 254) There’s a lot to dislike about lockdown but top of my list is my bf cutting his own hair. He now refuses to go to… 255) Link for stepson’s latest project. soul music lockdown 256) "Honestly, I was gonna hang them with care, but I think I'll just use tacks or a staple gun this year."Christmas Covid Lockdown 257) Link for stepsons latest project! soul music lockdown 258) The Dust Bunnies are proud to release the digitally remastered version of Lockdown (baby). CVD19 PremierFord C… 259) The whole western world is going back into full Lockdown so it would h… 260) With the announcment of the new provincial lockdown starting Dec 26, 2020, we wanted to give you a heads up on how we… 261) In 5th place in the countdown of our most read blogs in 2020, Dr Jinhyun Hong analyses the effects of the lockdown… 262) Air Pollution killed 10 TIMES more people in India 2019 than COVID-19 did in all of 2020. 1.96 Million died from air polluti… 263) Same here Barry. At least with the initial lockdown, we had fairly decent weather we could enjoy. S… 264) Merry X-Mas to all of you and thank you so much for your music 🙏😊.❄🌟🎁🎄💫🎅🏼🌟❄… 265) NUman saved up pretty good during the lockdown. Thanks to ghar ka khaana and paise bachana. Did you?numedia digitaladver… 266) ASPHER President is 'Planning for an Outbreak of Health', but first we must muddle through this Christmas s… 267) NUman saved up pretty good during the lockdown. Thanks to ghar ka khaana and paise bachana. Did you?numedia digitaladver… 268) With the announcment of the new provincial lockdown starting Dec 26, 2020, we wanted to give you a heads up on how we… 269) NUman saved up pretty good during the lockdown. Thanks to ghar ka khaana and paise bachana. Did you?numedia… 270) Air Pollution killed 10 TIMES more people in India 2019 than COVID-19 did in all of 2020. 1.96 Million died from air polluti… 271) ANYBODY WANNA REMEMBER THIS? “DR”... (if that’s even his real name) FAUCI BEING PROTESTED BY THE GREAT BIG VERY PRO… 272) This is great for those who are familiar with computers, but my 94 year-old-mom would be completely lost without as… 273) Just announced. New online event based on my book Feel Better, No Matter What. lawofattrac… 274) A major tourist attraction in Ramanathapuram district, Arichalmunai and Dhanushkodi were out of bounds for touris…
# Printing negative tweets
print('Printing negative tweets:\n')
j=1
sortedDF = df.sort_values(by=['Polarity'],ascending=False) #Sort the tweets
for i in range(0, sortedDF.shape[0] ):
if( sortedDF['Analysis'][i] == 'Negative'):
print(str(j) + ') '+sortedDF['text'][i])
print()
j=j+1
Printing negative tweets: 1) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 2) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 3) 🧠 You take $40k raises this year. Lock us down. Sent billions to foreign countries. 5000 pages of bs and you think… 4) Now you can understand from the time Lockdown started is under attack 4m all ends and this is now a deadly co… 5) How these people managed to stay alive during this pandemic? All of those months around a deadly virus and they are… 6) EcoFriendlyChristmas due to CoronavirusStrain & lockdown this year no celebration. Pray to lord… 7) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 8) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 9) Me: No more political tweets over Christmas..it’s the season of goodwill.Also me: When I find out Matt Hancock is… 10) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 11) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 12) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 13) Months... Months of lockdowns... Was this miracle vaccine approved so the vulnerable are vaccinated and the rest c… 14) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 15) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 16) Socially distant dancing happens every day on our road at 11am during lockdown. This was day seven.Covid19 StayHom… 17) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 18) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 19) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 20) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 21) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 22) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 23) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 24) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 25) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 26) So labour MPs want to lockdown and smash our economy further and hurt those with mental health issues.. and those… 27) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 28) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 29) Panic buying gone mad at Waitrose Salisbury covid lockdown brexit panicbuying salisbury wiltshirelife 30) EVENT REWIND: Parenting During Lockdown - not easy is it! we're no stranger to it here and it was also t… 31) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 32) Break Out of Airfield Encampment 🤬Are they prisoners of war or Bloody lorry drivers 🤷♀️ Do you still think we aren… 33) The self-entitled it’s a world wide theme. Covid Lockdown 34) My leader was the first person to help poor people farmers and Middle class people migrants and farmers at… 35) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 36) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 37) In Nigeria, citizens are frustrated with lockdown side effects. Many are concerned about food scarcity — with Sleepy … 38) Significant lessons from Arsenal, Manchester City Tuesday night game - Sport wizkid… 39) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 40) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 41) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 42) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 43) New Video! Share far and wide. COVIDSecondWave COVID19 lockdown COVIDー19 3 studies show failure of Lockdowns… 44) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 45) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 46) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 47) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 48) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 49) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 50) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 51) EcoFriendlyChristmas due to CoronavirusStrain & lockdown this year no celebration. Pray… 52) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 53) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 54) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 55) Airports being closed ... Ports being closed ... EuroTunnel being closed ... Christmas has been cancelled and we ar… 56) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 57) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 58) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 59) Powerlifting At Home- DB row in bent 4x10 with a dead stop powerliftingAtHome TrainAnywhere lockdown final dance is for… 60) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 61) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 62) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 63) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 64) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 65) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 66) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 67) I read, the rich all have ‘handlers’. To keep them in line. HATE THAT. I WILL NEVER BE NOBODYS BIT*H.RATHER BE… 68) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 69) It’s been a long weird year and this song would not have been written during other cicumstances. blues lockdown… 70) is not aware of ground realiti… 71) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 72) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 73) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 74) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 75) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-scient… 76) Bruce Pardy: ‘Obey the science’ has come to mean 'Believe what we tell you and do as you are told'. It is an anti-s… 77) Going crazy with the lockdown? Escape and travel to A KINGDOM BY THE SEA. "City boy take me away, back to the country where… 78) Just a reminder that to date less than 2,000 people of all ages, with no underlying health conditions, have died of… 79) DO NOT ACCEPT THE MARK OF THE BEAST.DO NOT BE AFRAID OF NOBODY.YOU ARE A SOVEREIGN BEING AND DESERVE COMPLETE F… 80) lockdown Some people will not agree with this but instead of dribs and drabs let's lock down the country for a mon… 81) Situation is being out of control daily above 50 deaths happens 1000 case everyday do something otherwise our count… 82) I last slept with my wife 10 years ago, I’m starving seriously says 70yr-old man tells court - … 83) 2021 is going to be just as shit as 2020 isn’t it? COVIDSecondWave covid lockdown tier4 tier5 Tier3 84) Socially distant dancing happens every day on our road at 11am during lockdown. This was day seven.Covid19 StayHom… 85) I last slept with my wife 10 years ago, I’m starving seriously says 70yr-old man tells court - … 86) Powerlifting At Home- DB row in bent 4x10 with a dead stop powerliftingAtHome TrainAnywhere lockdown final dance is for… 87) My leader was the first person to help poor people farmers and Middle class people migrants and farmers at… 88) Lockdown Lock down the Brexiteers 🇬🇧BRINO incoming...BorisJohnson Surrenders to ALL EU demands… 89) You can tell the gays that are in tier 4. Half naked pics all over the place 🤑🙄 lockdown tier4 90) Isn't it strange that whatever the problem facing society, whether it be terrorism, climate change or a novel virus, t… 91) Looking back on 2020 – the year of remote working lockdown workfromhome workingfromhome C… 92) Lockdown from iPhone11ProMax - not hard to find beauty down here 93) I last slept with my wife 10 years ago, I’m starving seriously says 70yr-old man tells court - … 94) I last slept with my wife 10 years ago, I’m starving seriously says 70yr-old man tells court -… 95) Lockdown got me drawing shit again....here’s as Derek tier4 lockdown drawingoftheday 96) I haven't Oneplus Mobile andThis isn't a secret, Becoz ofMy Economically Lockdownbut it's May be Fulfilled by… 97) Leaden lockdown skies highbury london but still the ice cream man cometh, with bells. Memories of old pal Tom Mo… 98) "We should shut down the entire economy if it will save one life."How do we know what life a lockdown saves when… 99) Global video conferencing market size expected to reach $50 billion by 2025Only £85/$115… 100) Beautiful rendition of “In the Bleak Midwinter” for Christmas by the harp quintet DPStrings - recorded by means of… 101) Am I missing something? makes a flying visit to Britain: … 102) Powerlifting at home Day 2- banded sumo. Again, pay attention to shoulders above the ‘bar’. I did put there few wrong reps… 103) Heartbreaking letter from a mother to her daughter who had a violent partner. The Family Rights Group do such good work… 104) Yes that's the vibe isn't it? I think it'll go National after Xmas. Only a dumb fuck would stick t… 105) My leader was the first person to help poor people farmers and Middle class people migrants and farmers at… 106) Well it is, Police at Dover trying to speak with foreign drivers. Not understood, s… 107) Covid_19 death figures in the UK are of course horrible, but they are (both cases & deaths) massively skewed becau… 108) My leader was the first person to help poor people farmers and Middle class people migrants and farmers at… 109) My leader was the first person to help poor people farmers and Middle class people migrants and farmers at… 110) My leader was the first person to help poor people farmers and Middle class people migrants and farmers at… 111) In Nigeria, citizens are frustrated with lockdown side effects. Many are concerned about food scarcity — with Sleepy … 112) My leader was the first person to help poor people farmers and Middle class people migrants and farmers at… 113) when running late to catch a , before lockdown 114) COVID20 vui2020 This is extremely worrying. VIU2020 has mutated rapidly. lockdown required nationwide. How long… 115) My leader was the first person to help poor people farmers and Middle class people migrants and farmers at… 116) With restaurants & hotels closed due to the ongoing COVID19 driven lockdown, Indian vegetable exporters expec… 117) Assassins creed 3: ✔. Next: Assassins Creed 4 Black Flag. lockdown Lockdown2 assoutforBiden NintendoSwitch… 118) You are destroying your city with your lockdown
for index, row in df.iterrows():
if row['Analysis'] == 'Positive':
plt.scatter(row['Polarity'], row['Subjectivity'], color="green")
elif row['Analysis'] == 'Negative':
plt.scatter(row['Polarity'], row['Subjectivity'], color="red")
elif row['Analysis'] == 'Neutral':
plt.scatter(row['Polarity'], row['Subjectivity'], color="blue")
plt.title('Twitter Sentiment Analysis')
plt.xlabel('Polarity')
plt.ylabel('Subjectivity')
# add legend
plt.show()
# Print the percentage of positive tweets
ptweets = df[df.Analysis == 'Positive']
ptweets = ptweets['text']
ptweets
round( (ptweets.shape[0] / df.shape[0]) * 100 , 1)
45.7
# Print the percentage of negative tweets
ntweets = df[df.Analysis == 'Negative']
ntweets = ntweets['text']
ntweets
round( (ntweets.shape[0] / df.shape[0]) * 100, 1)
19.7
# Show the value counts
df['Analysis'].value_counts()
Positive 274 Neutral 208 Negative 118 Name: Analysis, dtype: int64
# Plotting and visualizing the counts
plt.title('Sentiment Analysis')
plt.xlabel('Sentiment')
plt.ylabel('Counts')
df['Analysis'].value_counts().plot(kind = 'bar',color='red')
plt.show()
1) To solve this part I choosen the hashtag #Lockdown
2) To collect the tweets from the twitter we need twitter acess token keys and secret keys.
3) Using above keys and by using tweepy API. I was able to collect the tweets
4) Once after collecting tweets I cleaned the tweets (removed URLs) as suggested by using python functions and later on by using Textblob library I calcluated the Polarity and subjectivity values
5) Plotted a word cloud as well as mentioned postive anb negative tweets
As per my analysis people are feeling postive. But on other hand it is completely depends on lifesstyle and how each individual responds. But considering the transmission rate I feel covid lockdown is best in its own significant factors